<?php
namespace App\Models\Tarifas\Acabados;

use CodeIgniter\Database\BaseBuilder;

use CodeIgniter\Model;

class ServicioAcabadoModel extends Model
{
    protected $table = 'servicios_acabado';
    protected $primaryKey = 'id';
    protected $useSoftDeletes = true;
    protected $allowedFields = ['acabado_cubierta', 'acabado_sobrecubierta', 'nombre', 'comentarios', 'mostrar_en_presupuesto_cliente', 'user_updated_id', 'created_at', 'updated_at', 'deleted_at'];
    protected $useTimestamps = true;

    protected $dateFormat = 'datetime';
    protected $createdField = 'created_at';
    protected $updatedField = 'updated_at';
    protected $deletedField = 'deleted_at';

    protected $returnType = 'App\Entities\Tarifas\Acabados\ServicioAcabadoEntity';

    protected $validationRules = [
        "nombre" => [
            "label" => "ServicioAcabado.nombre",
            "rules" => "trim|required|max_length[100]",
        ],
    ];

    public function getDatatableQuery(): BaseBuilder
    {
        $builder = $this->db
            ->table($this->table . " t1")
            ->select(
                "t1.id,
                t1.nombre,
                t1.acabado_cubierta,
                t1.acabado_sobrecubierta,
                t1.mostrar_en_presupuesto_cliente,
                CONCAT(users.first_name, ' ', users.last_name) as user_updated,
                t1.updated_at",
            )
            ->join("users", "t1.user_updated_id = users.id", "left")
            ->where("t1.deleted_at", null);
        return $builder;
    }
}


