<?php
namespace App\Entities\Presupuestos;

use App\Entities\Tarifas\TarifaextraEntity;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Tarifas\Maquinas\TarifaExtraMaquinaModel;
use App\Models\Tarifas\TarifaextraModel;
use CodeIgniter\Entity;

class PresupuestoServiciosExtraEntity extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "presupuesto_id" => null,
        "tarifa_extra_id" => null,
        "precio_total" => null,
        "margen" => null,
        "created_at" => null,
        "updated_at" => null,
    ];
    protected $casts = [
        "presupuesto_id" => "int",
        "tarifa_extra_id" => "int",
        "precio_total" => "float",
        "margen" => "float",
    ];

    public function maquinas() : array 
    {
        $m = model(TarifaExtraMaquinaModel::class);
        $tarifa_maquinas = $m->where("tarifa_extra_id",$this->attributes["tarifa_extra_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() : TarifaextraEntity 
    {
        $m = model(TarifaextraModel::class);
        return $m->find($this->attributes["tarifa_extra_id"]);
    }
}
