<?php

declare(strict_types=1);

namespace Mapper;

use \Feast\BaseMapper;
use \Feast\BaseModel;
use \Feast\Exception\DatabaseException;
use \Model\{name};

class {name}{classExtra} extends BaseMapper
{
    protected const OBJECT_NAME = {name}::class;
    protected const PRIMARY_KEY = '{primaryKey}';
    public const TABLE_NAME = '{table}';
{connection}
    /**
     * @param int|string $value
     * @param bool $validate
     * @return ?{name}
     * @throws DatabaseException
     */
    public function findByPrimaryKey(int|string $value, bool $validate = false): ?{name}
    {
        throw new DatabaseException('No primary key specified for ' . static::TABLE_NAME); 
    }
    
    /**
     * Delete record by Model. Uses primary key.
     *
     * @param BaseModel $record
     * @return int
     * @throws DatabaseException
     */
    public function delete(BaseModel $record): int
    {
        throw new DatabaseException('No primary key specified for ' . static::TABLE_NAME); 
    }
    /**
     * Save model to database.
     *
     * @param BaseModel $record
     * @param bool $forceUpdate
     * @throws DatabaseException
     */
    public function save(BaseModel $record, bool $forceUpdate = false): void
    {
        // @todo: Create save method
        throw new DatabaseException('Save method not yet implemented for ' . static::class);
    }

    /**
     * This method is called when a Model is saved.
     *
     * Update this to call actions on save.
     *
     * @param {name} $record
     * @param bool $new
     */
    protected function onSave({name} $record, bool $new = true): void
    {
    }

    /**
     * This method is called when a Model is deleted.
     *
     * Update this to call actions on deletion.
     *
     * @param {name} $record
     */
    protected function onDelete({name} $record): void
    {
    }
}
