<?php
namespace App\Entities\Clientes;

use CodeIgniter\Entity;
use App\Models\Clientes\ClienteModel;
use App\Models\Configuracion\PaisModel;

class ClienteDireccionesEntity extends \CodeIgniter\Entity\Entity
{
    protected $attributes = [
        "id" => null,
        "cliente_id" => null,
        "alias" => null,
        "att" => null,
        "email" => null,
        "direccion" => null,
        "pais_id" => null,
        "provincia" => null,
        "municipio" => null,
        "cp" => null,
        "telefono" => null,
    ];
    protected $casts = [
        "cliente_id" => "int",
        "pais_id" => "int",
        "cp" => "int",
    ];

    public function getClienteNombre(): ?string
    {
        if (!$this->cliente_id) {
            return null;
        }

        $clienteModel = model(ClienteModel::class);
        $cliente = $clienteModel->find($this->cliente_id);

        return $cliente ? $cliente->nombre : null;
    }

    public function getPaisNombre(): ?string
    {
        if (!$this->pais_id) {
            return null;
        }

        $paisModel = model(PaisModel::class);
        $pais = $paisModel->find($this->pais_id);

        return $pais ? $pais->nombre : null;
    }

}
