<?php
namespace App\Entities\Configuracion;

use App\Models\Configuracion\MaquinasPapelesImpresionModel;
use App\Models\Configuracion\PapelGenericoModel;
use App\Models\Configuracion\PapelImpresionMargenModel;
use App\Models\Configuracion\PapelImpresionTipologiaModel;
use CodeIgniter\Entity;
use CodeIgniter\Model;

class PapelImpresion extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "papel_generico_id" => null,
        "nombre" => null,
        "defecto" => false,
        "referencia" => null,
        "mano" => null,
        "espesor" => 0.0,
        "gramaje" => null,
        "precio_tonelada" => null,
        "interior" => true,
        "bn" => true,
        "color" => true,
        "cubierta" => false,
        "sobrecubierta" => false,
        "guardas" => false,
        "inkjet" => false,
        "rotativa" => false,
        "isActivo" => true,
        "use_in_client" => false,
        "use_for_tapa_dura" => false,
        "is_deleted" => 0,
        "created_at" => null,
        "updated_at" => null,
    ];
    protected $casts = [
        "papel_generico_id" => "int",
        "defecto" => "boolean",
        "mano" => "float",
        "espesor" => "float",
        "gramaje" => "float",
        "precio_tonelada" => "float",
        "interior" => "boolean",
        "bn" => "boolean",
        "color" => "boolean",
        "cubierta" => "boolean",
        "sobrecubierta" => "boolean",
        "guardas" => "boolean",
        "rotativa" => "boolean",
        "isActivo" => "boolean",
        "use_in_client" => "boolean",
        "use_for_tapa_dura" => "boolean",
        "is_deleted" => "int",
    ];

    public function tipologia() : ?array
    {
        $m = model(PapelImpresionTipologiaModel::class);
        return $m->asArray()->where('papel_impresion_id',$this->attributes["id"])->findAll();
    }
    public function maquinas_impresion() : ?array
    {
        $m = model(MaquinasPapelesImpresionModel::class);
        return $m->asArray()->where('papel_impresion_id',$this->attributes["id"])->findAll();
    } 
    public function margen() : ?array
    {
        $m = model(PapelImpresionMargenModel::class);
        return $m->asArray()->where('papel_impresion_id',$this->attributes["id"])->findAll();
    }
    public function papel_generico() : ?PapelGenerico
    {
        $m = model(PapelGenericoModel::class);
        return $m->find($this->attributes["papel_generico_id"]);
    }
    public function getPapelCodeOt() : ?string
    {
        $code_ot = $this->papel_generico()->code_ot;
        $gramaje = $this->attributes["gramaje"];
        return implode(" ",[$code_ot,$gramaje]);
    }
}
