<?php


namespace App\Models;

use App\Entities\Exame\Exame;
use App\Utils\DateUtils;

class ExameModel extends ModelEntity {
	protected $table = 'exame';
	protected $primaryKey = 'id';
	protected $returnType = 'array';
	protected $allowedFields = [ 
			'nome'
	];
	protected $useSoftDeletes = false;
	protected $skipValidation = true;
	protected $useTimestamps = false;

	// protected $createdField = 'criado_em';
	// protected $updatedField = 'alterado_em';
	public function registerExame(Exame $exame): void {

		$data = $exame->toArray( true );
		$id_exame = $this->insert( $data );
		$exame->setId( $id_exame );

	}

	public function updateExameByID(int $id_exame, Exame $exame): bool {

		$data = $exame->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;

	}

}
