<?php

namespace App\Entities\Configuracion;

use App\Models\Configuracion\ImposicionEsquemaModel;
use CodeIgniter\Entity;

class Imposicion extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "ancho" => null,
        "alto" => null,
        "unidades" => null,
        "orientacion" => null,
        "maquina" => null,
        "etiqueta" => null,
        "imposicion_esquema_id" => null
    ];
    protected $casts = [
        "ancho" => "int",
        "alto" => "int",
        "unidades" => "?int",
        "imposicion_esquema_id" => "?int"

    ];

    public function getFullName(): string
    {
        $ancho_x_alto = $this->attributes["ancho"] . "x" . $this->attributes["alto"];
        $unidades = $this->attributes["unidades"] ?? "";
        $orientacion = $this->attributes["orientacion"] ?? "";
        return implode("_", [$ancho_x_alto, $unidades, $orientacion]);
    }
    public function withImposicionEsquema(): self
    {

        $this->attributes["imposicion_esquema"] = $this->imposicion_esquema();
        return $this;
    }
    public function imposicion_esquema(): ?ImposicionEsquemaEntity
    {
        $esquema = null;
        if ($this->attributes["imposicion_esquema_id"]) {
            $m = model(ImposicionEsquemaModel::class);
            $esquema = $m->find($this->attributes["imposicion_esquema_id"]);
        }
        return $esquema;
    }
}
