<?php
namespace App\Entity\BC;
use App\Repository\BC\ImportLogRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
#[ORM\Entity(repositoryClass: ImportLogRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ORM\Index(name: 'idx_item_no_created', columns: ['item_no', 'created_at'])]
class ImportLog
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING, length: 255)]
private string $id;
#[ORM\Column(type: Types::STRING, length: 64)]
private string $itemNo;
#[ORM\Column(type: Types::TEXT)]
private string $itemData;
#[ORM\Column(type: Types::STRING, length: 64, nullable: true)]
private ?string $productAffected = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $variantsAffected = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $errors = null;
#[ORM\Column(type: Types::JSON, nullable: true)]
private ?array $warnings = null;
#[ORM\Column(type: 'datetime_immutable')]
private \DateTimeImmutable $createdAt;
public function __construct(string $itemNo, string $itemData, array $errors = [])
{
$uuid = Uuid::uuid1();
$this->id = sprintf('%s_%s', $itemNo, $uuid->toString());
$this->itemNo = $itemNo;
$this->itemData = $itemData;
$this->errors = $errors;
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): string
{
return $this->id;
}
public function getUuid(): UuidInterface
{
$uuidPart = explode('_', $this->id)[1];
return Uuid::fromString($uuidPart);
}
public function getItemNo(): string
{
return $this->itemNo;
}
public function getItemData(): string
{
return $this->itemData;
}
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
public function setProductAffected(?string $productAffected): void
{
$this->productAffected = $productAffected;
}
public function getProductAffected(): ?string
{
return $this->productAffected;
}
public function setVariantsAffected(?array $variantsAffected): void
{
$this->variantsAffected = $variantsAffected;
}
public function addVariantAffected(string $variantNo): void
{
$this->variantsAffected ??= [];
$this->variantsAffected[] = $variantNo;
}
public function getVariantsAffected(): ?array
{
return $this->variantsAffected;
}
public function setErrors(?array $errors): void
{
$this->errors = $errors;
}
public function addError(string $error): void
{
$this->errors ??= [];
$this->errors[] = $error;
}
public function getErrors(): ?array
{
return $this->errors;
}
public function setWarnings(?array $warnings): void
{
$this->warnings = $warnings;
}
public function addWarning(string $warning): void
{
$this->warnings ??= [];
if (in_array($warning, $this->warnings, true)) {
return;
}
$this->warnings[] = $warning;
}
public function getWarnings(): ?array
{
return $this->warnings;
}
}