<?php

namespace App\Entities\Produccion;

use App\Entities\Usuarios\UserEntity;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Entity\Entity;

class OrdenTrabajoUserEntity extends Entity
{
    protected $datamap = [];
    protected $dates   = ['created_at', 'updated_at', 'deleted_at'];

    protected $attributes = [
        "orden_trabajo_id" => null,
        "user_created_id" => null,
        "user_update_id" => null,
        //IMPRESION
        "interior_bn_user_id" => null,
        "interior_color_user_id" => null,
        "cubierta_user_id" => null,
        //ACABADO
        "plastificado_user_id" => null,
        "encuadernacion_user_id" => null,
        "corte_user_id" => null,
        "preparacion_interior_user_id" => null,
        "entrada_manipulado_user_id" => null,
        "cosido_user_id" => null,
        "solapa_user_id" => null,
        "grapado_user_id" => null,
        "retractilado_user_id" => null,
        "retractilado5_user_id" => null,
        "prototipo_user_id" => null,
        "marcapaginas_user_id" => null,
        "espiral_user_id" => null,

        //FERRO
        "pendiente_ferro_user_id" => null,
        "ferro_en_cliente_user_id" => null,
        "ferro_ok_user_id" => null,
        //ENVIO
        "embalaje_user_id" => null,
        "envio_user_id" => null,
        //PREIMPRESION
        "pre_formato_user_id" => null,
        "pre_lomo_user_id" => null,
        "pre_solapa_user_id" => null,
        "pre_codbarras_user_id" => null,
        "pre_imposicion_user_id" => null,
        //UNUSED
        "inaplazable_revised_change_user_id" => null, //!DELETE
        "ferro_disponible_hecho_user_id" => null, //!DELETE
        "ferro_entregado_user_id" => null, //!DELETE
        "pre_imprimir_user_id" => null, //!DELETE
        "ferro_disponible_ok_user_id" => null, //!DELETE
    ];
    // protected array $casts = [
    //     "orden_trabajo_id" => "integer",
    //     "user_created_id" => "?integer",
    //     "user_update_id" => "?integer",
    //     "inaplazable_revised_change_user_id" => "?integer",
    //     "ferro_disponible_hecho_user_id" => "?integer",
    //     "ferro_disponible_ok_user_id" => "?integer",
    //     "ferro_entregado_user_id" => "?integer",
    //     "pendiente_ferro_user_id" => "?integer",
    //     "ferro_en_cliente_user_id" => "?integer",
    //     "ferro_ok_user_id" => "?integer",
    //     "interior_bn_user_id" => "?integer",
    //     "interior_color_user_id" => "?integer",
    //     "preparacion_interior_user_id" => "?integer",
    //     "cubierta_user_id" => "?integer",
    //     "plastificado_user_id" => "?integer",
    //     "encuadernacion_user_id" => "?integer",
    //     "corte_user_id" => "?integer",
    //     "embalaje_user_id" => "?integer",
    //     "entrada_manipulado_user_id" => "?integer",
    //     "pre_formato_user_id" => "?integer",
    //     "pre_lomo_user_id" => "?integer",
    //     "pre_solapa_user_id" => "?integer",
    //     "pre_codbarras_user_id" => "?integer",
    //     "pre_imposicion_user_id" => "?integer",
    //     "pre_imprimir_user_id" => "?integer"
    // ];

    public function userBy(string $key): ?UserEntity
    {
        $user = null;
        if (isset($this->attributes[$key])) {

            if ($this->attributes[$key]) {
                $m = model(UserModel::class);
                $user = $m->find($this->attributes[$key]);
            }
        }
        return $user;
    }
    public function getPlastificadoBy(): ?UserEntity
    {
        return $this->userBy('plastificado_user_id');
    }
}
