<?php
namespace App\Domain\Entity;
use App\Domain\Enum\TipoProcedimientoTramiteEnum;
use App\Shared\Domain\ApplicationCore\Interfaces\EntityInterface;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
class Expediente implements EntityInterface
{
private ?Uuid $id = null;
private ?string $key = null;
private ?string $nombre = null;
/**
* @var string|null
* @Assert\NotBlank(message="not_blank", groups={"explicit_check"})
*
* FIX-260518-101: el constraint queda en el grupo "explicit_check"
* en lugar de Default, para que el flujo Sonata create no lo dispare
* antes del flush. postPersist (GenerateNumExpCommandHandler) genera
* el numero despues del persist. Quien necesite exigir el numero
* (API, console, batch) debe validar pasando explicitamente
* ['explicit_check'] al ValidatorInterface.
*/
private ?string $numeroExpediente = null;
private ?string $descripcion = null;
private ?DateTimeInterface $createdAt = null;
private ?DateTimeInterface $updatedAt = null;
private ?DateTimeInterface $deletedAt = null;
private ?EstadoExpediente $estadoExpediente = null;
private ?ExpedienteCabecera $cabecera = null;
/**
* @var MetadataExpediente|null
* @Assert\NotBlank(message="not_blank")
*/
private ?MetadataExpediente $metadata = null;
private ?SonataUserUser $creador = null;
private ?Entidad $entidad = null;
private ?DocumentacionRegistro $solicitud = null;
private Collection $tramites;
private Collection $minutas;
private Collection $responsables;
private Collection $registros;
private Collection $representacions;
public function __construct()
{
$this->tramites = new ArrayCollection();
$this->minutas = new ArrayCollection();
$this->responsables = new ArrayCollection();
$this->registros = new ArrayCollection();
$this->representacions = new ArrayCollection();
}
public function __toString(): string
{
return $this->getNumeroExpediente()??'X/0000/2024';
}
public function getKey(): ?string
{
return $this->key;
}
public function setKey(?string $key): static
{
$this->key = $key;
return $this;
}
public function getNumeroExpediente(): ?string
{
return $this->numeroExpediente;
}
public function setNumeroExpediente(?string $numeroExpediente): static
{
$this->numeroExpediente = $numeroExpediente;
return $this;
}
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(?string $nombre): static
{
$this->nombre = $nombre;
return $this;
}
public function getDescripcion(): ?string
{
return $this->descripcion;
}
public function setDescripcion(?string $descripcion): static
{
$this->descripcion = $descripcion;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): static
{
$this->deletedAt = $deletedAt;
return $this;
}
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return Collection<int, Tramite>
*/
public function getTramites(): Collection
{
return $this->tramites;
}
public function addTramite(Tramite $tramite): static
{
if (!$this->tramites->contains($tramite)) {
$this->tramites->add($tramite);
$tramite->setExpediente($this);
}
return $this;
}
public function removeTramite(Tramite $tramite): static
{
if ($this->tramites->removeElement($tramite)) {
// set the owning side to null (unless already changed)
if ($tramite->getExpediente() === $this) {
$tramite->setExpediente(null);
}
}
return $this;
}
/**
* @return Collection<int, Minuta>
*/
public function getMinutas(): Collection
{
return $this->minutas;
}
public function addMinuta(Minuta $minuta): static
{
if (!$this->minutas->contains($minuta)) {
$this->minutas->add($minuta);
$minuta->setExpediente($this);
}
return $this;
}
public function removeMinuta(Minuta $minuta): static
{
if ($this->minutas->removeElement($minuta)) {
// set the owning side to null (unless already changed)
if ($minuta->getExpediente() === $this) {
$minuta->setExpediente(null);
}
}
return $this;
}
public function getEstadoExpediente(): ?EstadoExpediente
{
return $this->estadoExpediente;
}
public function setEstadoExpediente(?EstadoExpediente $estadoExpediente): static
{
$this->estadoExpediente = $estadoExpediente;
return $this;
}
public function getMetadata(): ?MetadataExpediente
{
return $this->metadata;
}
public function setMetadata(?MetadataExpediente $metadata): static
{
$this->metadata = $metadata;
return $this;
}
public function getCreador(): ?SonataUserUser
{
return $this->creador;
}
public function setCreador(?SonataUserUser $creador): static
{
$this->creador = $creador;
return $this;
}
public function getEntidad(): ?Entidad
{
return $this->entidad;
}
public function setEntidad(?Entidad $entidad): static
{
$this->entidad = $entidad;
return $this;
}
/**
* @return Collection<int, SonataUserUser>
*/
public function getResponsables(): Collection
{
return $this->responsables;
}
public function addResponsable(SonataUserUser $responsable): static
{
if (!$this->responsables->contains($responsable)) {
$this->responsables->add($responsable);
}
return $this;
}
public function removeResponsable(SonataUserUser $responsable): static
{
$this->responsables->removeElement($responsable);
return $this;
}
public function getCabecera(): ?ExpedienteCabecera
{
return $this->cabecera;
}
public function setCabecera(?ExpedienteCabecera $cabecera): static
{
$this->cabecera = $cabecera;
return $this;
}
public function getTipo(): ?string
{
switch ($this->getTramites()?->last()->getProcedimiento())
{
case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_EC:
$return = 'EC';
break;
case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_M:
$return = 'M';
break;
case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_C:
$return = 'C';
break;
case TipoProcedimientoTramiteEnum::PROCEDIMIENTO_A:
$return = 'A';
break;
default:
$return = null;
break;
}
return $return;
}
public function getEmpresa(): ?string
{
$data = json_decode($this->getCustom(), true);
switch ($data['entidad'])
{
case 'EMPRESA':
case '0':
$tipo = 'E';
break;
case 'SECTOR':
case '1':
$tipo = 'S';
break;
default:
$tipo = '---';
break;
}
return $tipo;
}
public function getEmpresaNombre(): ?string
{
$data = json_decode($this->getCustom(), true);
switch ($data['entidad'])
{
case 'EMPRESA':
case '0':
$id = $data['empresa'];
break;
case 'SECTOR':
case '1':
$id = $data['sector'];
break;
default:
$id = null;
break;
}
return $id;
}
/**
* @return Collection<int, DocumentacionRegistro>
*/
public function getRegistros(): Collection
{
return $this->registros;
}
public function addRegistro(DocumentacionRegistro $registro): static
{
if (!$this->registros->contains($registro)) {
$this->registros->add($registro);
$registro->setExpediente($this);
}
return $this;
}
public function removeRegistro(DocumentacionRegistro $registro): static
{
if ($this->registros->removeElement($registro)) {
// set the owning side to null (unless already changed)
if ($registro->getExpediente() === $this) {
$registro->setExpediente(null);
}
}
return $this;
}
public function getFase():?string
{
return $this->getEstadoExpediente()?->getSubestado();
}
public function getSubFase():?string
{
return $this->getTramites()?->last()->getNombre();
}
public function getSolicitud(): ?DocumentacionRegistro
{
return $this->solicitud;
}
public function setSolicitud(?DocumentacionRegistro $solicitud): static
{
$this->solicitud = $solicitud;
return $this;
}
public function getCustom():?string
{
return $this->getSolicitud()?->getCustom()->getForm();
}
/**
* @return Collection<int, Representacion>
*/
public function getRepresentacions(): Collection
{
return $this->representacions;
}
public function addRepresentacion(Representacion $representacion): static
{
if (!$this->representacions->contains($representacion)) {
$this->representacions->add($representacion);
$representacion->setExpediente($this);
}
return $this;
}
public function removeRepresentacion(Representacion $representacion): static
{
if ($this->representacions->removeElement($representacion)) {
// set the owning side to null (unless already changed)
if ($representacion->getExpediente() === $this) {
$representacion->setExpediente(null);
}
}
return $this;
}
}