<?php
namespace App\Entities\Presupuestos;

use App\Entities\Tarifas\Acabados\TarifaAcabadoEntity;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Tarifas\Acabados\TarifaAcabadoModel;
use App\Models\Tarifas\Maquinas\TarifaAcabadoMaquinaModel;
use CodeIgniter\Entity;

class PresupuestoAcabadosEntity extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "presupuesto_id" => null,
        "tarifa_acabado_id" => null,
        "proveedor_id" => null,
        "precio_unidad" => null,
        "importe_minimo" => null,
        "importe_fijo" => null,
        "precio_total" => null,
        "margen" => null,
        "cubierta" => null,
        "sobrecubierta" => null,
        "faja" => null,
        "created_at" => null,
        "updated_at" => null,
    ];
    protected $casts = [
        "presupuesto_id" => "int",
        "tarifa_acabado_id" => "int",
        "proveedor_id" => "int",
        "precio_unidad" => "float",
        "importe_minimo" => "float",
        "importe_fijo" => "float",
        "margen" => "float",
        "cubierta" => "int",
        "sobrecubierta" => "int",
        "faja" => "int",
    ];

    public function maquinas() : array 
    {
        $m = model(TarifaAcabadoMaquinaModel::class);
        $tarifa_maquinas = $m->where("tarifa_acabado_id",$this->attributes["tarifa_acabado_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() : TarifaAcabadoEntity 
    {
        $m = model(TarifaAcabadoModel::class);
        return $m->find($this->attributes["tarifa_acabado_id"]);
    }
    
}
