<?php namespace App\Models;

use App\Utils\DateUtils;

class DocumentoGeradoModel extends ModelEntity
{
    protected $table = 'documentos_gerados';
    protected $primaryKey = 'id';
    protected $returnType = 'array';
    protected $allowedFields = [
        'url',
        'id_cliente',
        'id_pet',
        'descricao',
        'criado_em',
    ];
    protected $useSoftDeletes = false;
    protected $useTimestamps = false;
    protected $skipValidation = true;
    protected $createdField  = 'criado_em';
    protected $updatedField  = 'alterado_em';


    public function registerDocumentoGerado ($url, $id_pet, $id_cliente, $descricao) : bool {
        $sql = 'INSERT INTO documentos_gerados (
                    url,
                    id_cliente,
                    id_pet,
                    descricao,
                    criado_em
                ) VALUES ();
        ';
        $today = DateUtils::today();
        $values = "(
            '{$url}',      
            {$id_cliente},
            {$id_pet},   
            '{$descricao}',   
            '{$today}'
        )";

        $sql = str_replace('VALUES ()', "VALUES $values", $sql);
        $query = $this->db->query($sql);
        return $query->connID->affected_rows;
    }
}
