<?php
namespace App\Models\Configuracion;

class PaisModel extends \App\Models\BaseModel
{
    protected $table = "lg_paises";

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


    protected $allowedFields = ["nombre", "code", "code3", "moneda", "url_erp", "user_erp", "key_erp", "show_erp"];
    protected $returnType = "App\Entities\Configuracion\PaisEntity";

    public static $labelField = "nombre";

    protected $validationRules = [
        "code" => [
            "label" => "Paises.code",
            "rules" => "trim|required|max_length[2]|is_unique[lg_paises.code,id,{id}]",
        ],
        "code3" => [
            "label" => "Paises.code3",
            "rules" => "trim|max_length[3]",
        ],
        "key_erp" => [
            "label" => "Paises.keyErp",
            "rules" => "trim|max_length[255]",
        ],
        "moneda" => [
            "label" => "Paises.moneda",
            "rules" => "trim|required|max_length[3]",
        ],
        "nombre" => [
            "label" => "Paises.nombre",
            "rules" => "trim|required|max_length[255]",
        ],
        "url_erp" => [
            "label" => "Paises.urlErp",
            "rules" => "trim|max_length[255]",
        ],
        "user_erp" => [
            "label" => "Paises.userErp",
            "rules" => "trim|max_length[255]",
        ],
    ];

    protected $validationMessages = [
        "code" => [
            "is_unique" => "Paises.validation.code.is_unique",
            "max_length" => "Paises.validation.code.max_length",
            "required" => "Paises.validation.code.required",
        ],
        "code3" => [
            "max_length" => "Paises.validation.code3.max_length",
        ],
        "key_erp" => [
            "max_length" => "Paises.validation.key_erp.max_length",
        ],
        "moneda" => [
            "max_length" => "Paises.validation.moneda.max_length",
            "required" => "Paises.validation.moneda.required",
        ],
        "nombre" => [
            "max_length" => "Paises.validation.nombre.max_length",
            "required" => "Paises.validation.nombre.required",
        ],
        "url_erp" => [
            "max_length" => "Paises.validation.url_erp.max_length",
        ],
        "user_erp" => [
            "max_length" => "Paises.validation.user_erp.max_length",
        ],
    ];

    /**
     * Get resource data.
     *
     * @return \CodeIgniter\Database\BaseBuilder
     */
    public function getDatatableQuery()
    {
        $builder = $this->db
            ->table($this->table . " t1")
            ->select(
                "t1.id AS id, 
                    t1.nombre AS nombre, 
                    t1.code AS code, 
                    t1.code3 AS code3, 
                    t1.moneda AS moneda, 
                    t1.url_erp AS url_erp, 
                    t1.user_erp AS user_erp, 
                    t1.key_erp AS key_erp, 
                    t1.show_erp AS show_erp"
            );

        return $builder;
    }
}
