<?php namespace App\Models;

use App\Entities\GaleriaClassificacao\GaleriaClassificacao;
use App\Utils\DateUtils;

class GaleriaClassificacaoModel extends ModelEntity
{
    protected $table = 'galeria_classificacao';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $allowedFields = [
        'antes',
        'depois',
        'descricao'
    ];
    protected $useSoftDeletes = false;
    protected $skipValidation = true;
    protected $useTimestamps = false;
//    protected $createdField  = 'criado_em';
//    protected $updatedField  = 'alterado_em';

    public function registerGaleriaClassificacao (GaleriaClassificacao $galeria_classificacao) : void {
        $data = $galeria_classificacao->toArray(true);
        $id_exame = $this->insert($data);
        $galeria_classificacao->setId($id_exame);
    }

    public function updateGaleriaClassificacaoByID (int $id_exame, GaleriaClassificacao $galeria_classificacao) : bool {
        $data = $galeria_classificacao->toArray(true);
        $binds = ['id_exame' => $id_exame];
        $sets = $this->generateUpdateSets($data, $binds);
        $sql = "update exame $sets where exame.id = :id_exame:";
        $query = $this->db->query($sql, $binds);
        return $query->connID->affected_rows === 1;
    }
}
