<?php
namespace App\Entities\Presupuestos;

use App\Entities\Tarifas\TarifapreimpresionEntity;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Tarifas\Maquinas\TarifaPreimpresionMaquinaModel;
use App\Models\Tarifas\TarifapreimpresionModel;
use CodeIgniter\Entity;

class PresupuestoPreimpresionesEntity extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "presupuesto_id" => null,
        "tarifa_preimpresion_id" => null,
        "precio_total" => null,
        "margen" => null,
        "created_at" => null,
        "updated_at" => null,
    ];
    protected $casts = [
        "presupuesto_id" => "int",
        "tarifa_preimpresion_id" => "int",
        "precio_total" => "float",
        "margen" => "float",
    ];
    public function maquinas() : array 
    {
        $m = model(TarifaPreimpresionMaquinaModel::class);
        $tarifa_maquinas = $m->where("tarifa_preimpresion_id",$this->attributes["tarifa_preimpresion_id"])->findAll();
        $maquinaModel = model(MaquinaModel::class);
        $maquinas = [];
        foreach ($tarifa_maquinas as $key => $tarifa_maquina) {
            $maquinas[] = $maquinaModel->find($tarifa_maquina->maquina_id);
        }
        return $maquinas;
    }
    public function tarifa() : TarifapreimpresionEntity 
    {
        $m = model(TarifapreimpresionModel::class);
        return $m->find($this->attributes["tarifa_preimpresion_id"]);
    }
}
