<?php
namespace App\Entities\Configuracion;

use App\Models\Configuracion\MaquinasCallesModel;
use App\Models\Configuracion\MaquinasDefectoModel;
use App\Models\Configuracion\MaquinasPapelesImpresionModel;
use App\Models\Configuracion\MaquinasTarifasImpresionModel;
use CodeIgniter\Entity;
use PhpParser\Node\Expr\Cast\Array_;

class Maquina extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "nombre" => null,
        "is_padre" => false,
        "tipo" => null,
        "velocidad" => 0.0,
        "ancho" => 100.0,
        "alto" => 100.0,
        "ancho_impresion" => 0.0,
        "alto_impresion" => 0.0,
        "alto_click" => 0.0,
        "padre_id" => null,
        "min" => 1,
        "max" => 1000000,
        "duracion_jornada" => 8,
        "orden_planning" => 1,
        "is_rotativa" => false,
        "precio_tinta_negro" => 0.0,
        "is_inkjet" => false,
        "precio_tinta_color" => 0.0,
        "precio_tinta_cg" => 0.0,
        "velocidad_corte" => 0.0,
        "precio_hora_corte" => 0.0,
        "metrosxminuto" => 0.0,
        "forzar_num_formas_horizontales_cubierta" => null,
        "forzar_num_formas_verticales_cubierta" => null,
        "observaciones" => "",
        "is_deleted" => 0,
        "created_at" => null,
        "updated_at" => null,
        "user_created_id" => 0,
        "user_updated_id" => 0,
    ];
    protected $casts = [
        "is_padre" => "boolean",
        "velocidad" => "float",
        "ancho" => "?float",
        "alto" => "?float",
        "ancho_impresion" => "float",
        "alto_impresion" => "float",
        "alto_click" => "float",
        "padre_id" => "?int",
        "min" => "int",
        "max" => "int",
        "duracion_jornada" => "int",
        "orden_planning" => "int",
        "is_rotativa" => "boolean",
        "precio_tinta_negro" => "float",
        "is_inkjet" => "boolean",
        "precio_tinta_color" => "float",
        "precio_tinta_cg" => "float",
        "velocidad_corte" => "float",
        "precio_hora_corte" => "float",
        "forzar_num_formas_horizontales_cubierta" => "?int",
        "forzar_num_formas_verticales_cubierta" => "?int",
        "is_deleted" => "int",
        "user_created_id" => "int",
        "user_updated_id" => "int",
    ];

    public function papeles_impresion() : ?array
    {
        $m = model(MaquinasPapelesImpresionModel::class);
        return $m->asArray()->where('maquina_id',$this->attributes['id'])->findAll();
    }
    public function maquina_defecto(): ?array
    {
        $m = model(MaquinasDefectoModel::class);
        return $m->asArray()->where('maquina_id',$this->attributes['id'])->findAll();
    }
    public function maquina_calles() : ?array
    {
        $m = model(MaquinasCallesModel::class);
        return $m->asArray()->where('maquina_id',$this->attributes['id'])->findAll();
    }
    public function tarifas_impresion() : ?array
    {
        $m = model(MaquinasTarifasImpresionModel::class);
        return $m->asArray()->where('maquina_id',$this->attributes['id'])->findAll();  
    }
    public function withAll() : self
    {
        $this->attributes['papeles_impresion'] = $this->papeles_impresion();
        $this->attributes['maquina_calles'] = $this->maquina_calles();
        $this->attributes['maquina_defecto'] = $this->maquina_defecto();
        $this->attributes['tarifas_impresion'] = $this->tarifas_impresion();

        return $this;
    }
}
