<?php
namespace App\Entities\Tarifas\Acabados;

use App\Entities\Tarifas\Maquinas\TarifaAcabadoMaquinaEntity;
use App\Models\Tarifas\Maquinas\TarifaAcabadoMaquinaModel;
use CodeIgniter\Entity;

class TarifaAcabadoEntity extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "nombre" => null,
        "code" => null,
        "comment" => null,
        "precio_min" => 0,
        "importe_fijo" => 0,
        "mostrar_en_presupuesto" => 1,
        "mostrar_en_presupuesto_cliente" => 0,
        "acabado_cubierta" => 0,
        "acabado_sobrecubierta" => 0,
        "user_created_id" => 0,
        "user_updated_id" => 0,
        "is_deleted" => 0,
        "deleted_at" => null,
        "created_at" => null,
        "updated_at" => null,
    ];
    protected $casts = [
        "precio_min" => "float",
        "comment" => "string",
        "code" => "string",
        "importe_fijo" => "float",
        "user_created_id" => "int",
        "user_updated_id" => "int",
        "is_deleted" => "int",
    ];
    /**
     * Devuelve las maquinas asociadas a esta tarifa de acabado
     *
     * @return array<MaquinaEntity>
     */
    public function maquinas() : array
    {
        $m = model(TarifaAcabadoMaquinaModel::class);
        $ta_maquinas = $m->where('tarifa_acabado_id',$this->attributes['id'])->findAll();
        return array_map(fn(TarifaAcabadoMaquinaEntity $ta_maquina) => $ta_maquina->maquina(),$ta_maquinas);
    }

    public function isUVI(): bool 
    {
        return in_array($this->attributes["code"],["R3D","R2D"]);   
    }
}
