<?php namespace App\Models;

use App\Entities\Raca\Raca;
use App\Utils\DateUtils;

class RacaModel extends ModelEntity
{
    protected $table = 'raca';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $allowedFields = [
        'nome',
        'id_especie'
    ];
    protected $useSoftDeletes = false;
    protected $skipValidation = true;
    protected $useTimestamps = false;
//    protected $createdField  = 'criado_em';
//    protected $updatedField  = 'alterado_em';

    public function registerRaca (Raca $exame) : void {
        $data = $exame->toArray(true);
        $id_raca = $this->insert($data);
        $exame->setId($id_raca);
    }

    public function updateRacaByID (int $id_raca, Raca $exame) : bool {
        $data = $exame->toArray(true);
        $binds = ['id_raca' => $id_raca];
        $sets = $this->generateUpdateSets($data, $binds);
        $sql = "UPDATE raca $sets WHERE raca.id = :id_raca:";
        $query = $this->db->query($sql, $binds);
        return $query->connID->affected_rows === 1;
    }
}
