<?php

namespace App\Models\Clientes;

class ClientePlantillaPreciosModel extends \App\Models\BaseModel
{
    protected $table = "cliente_plantilla_precios";

    const SORTABLE = [
        0 => "t1.id",
        1 => "t1.nombre",
    ];

    /**
     * Whether primary key uses auto increment.
     *
     * @var bool
     */
    protected $useAutoIncrement = true;


    protected $allowedFields = ["nombre", "deleted_at", "created_at", "updated_at"];
    protected $returnType = "App\Entities\Clientes\ClientePlantillaPreciosEntity";

    protected $useTimestamps = true;
    protected $useSoftDeletes = true;
    protected $deletedField = 'deleted_at';

    protected $createdField = "created_at";

    protected $updatedField = "updated_at";

    public static $labelField = "nombre";

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

    protected $validationMessages = [
        "nombre" => [
            "max_length" => "ClientePrecios.validation.max_length",
        ],
    ];


     /**
     * Get resource data.
     *
     * @param array $search
     *
     * @return \CodeIgniter\Database\BaseBuilder
     */
    public function getResource($search = [])
    {
        $builder = $this->db
            ->table($this->table . " t1")
            ->select(
                "t1.id as id, t1.nombre AS nombre"
            );

        $builder->where('t1.deleted_at', null);

        if (empty($search))
            return $builder;
        else {
            $builder->groupStart();
            foreach ($search as $col_search) {
                $builder->like(self::SORTABLE[$col_search[0]], $col_search[2]);
            }
            $builder->groupEnd();
            return $builder;
        }
    }

}
