<?php

namespace App\Models;

use CodeIgniter\Model;

class CatalogosMHModel extends Model
{
    protected $DBGroup          = 'adminDb';
    protected $table            = 'catalogosmh';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $protectFields    = true;
    protected $allowedFields    = [
        'id_catalogo',
        'campo_catalogo',
        'codigo_catalogo',
        'valor1_catalogo',
        'valor2_catalogo'
    ];

    // Dates
    protected $useTimestamps = false;
    protected $dateFormat    = 'datetime';
    protected $createdField  = 'created_at';
    protected $updatedField  = 'updated_at';
    protected $deletedField  = 'deleted_at';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages   = [];
    protected $skipValidation       = false;
    protected $cleanValidationRules = true;

    // Callbacks
    protected $allowCallbacks = true;
    protected $beforeInsert   = [];
    protected $afterInsert    = [];
    protected $beforeUpdate   = [];
    protected $afterUpdate    = [];
    protected $beforeFind     = [];
    protected $afterFind      = [];
    protected $beforeDelete   = [];
    protected $afterDelete    = [];

    public function getValue($campo, $codigo, $valor2 = null)
    {
        $where['campo_catalogo'] = $campo;
        $where['codigo_catalogo'] = $codigo;
        if($valor2 != null){
            $where['valor2_catalogo'] = $valor2;
        }

        $val = $this->db->table('catalogosmh')->where($where)->get()->getResult();
       return $val ? $val[0]->valor1_catalogo : null;
    }
}
