<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\User\Model;

use CpCreation\VitiCore\Behavior\HasTimestamp;
use CpCreation\VitiCore\Behavior\Impl\Timestamp;
use CpCreation\VitiCore\User\Repository\ImportedClientImportRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;

#[ORM\Entity(repositoryClass: ImportedClientImportRepository::class)]
#[ORM\Table(name: 'user_imported_client_import')]
#[ORM\HasLifecycleCallbacks]
class ImportedClientImport implements HasTimestamp
{
    use Timestamp;

    #[ORM\Id]
    #[ORM\Column(type: 'uuid')]
    #[ORM\GeneratedValue(strategy: 'NONE')]
    private UuidInterface $id;

    #[ORM\Column(type: 'string', length: 255)]
    private string $originalFilename;

    #[ORM\Column(type: 'string', length: 255, unique: true)]
    private string $storedFilename;

    #[ORM\Column(type: 'string', length: 127, nullable: true)]
    private ?string $contentType;

    #[ORM\Column(type: 'integer')]
    private int $fileSize;

    #[ORM\Column(type: 'integer')]
    private int $totalRows;

    #[ORM\Column(type: 'integer')]
    private int $createdCount;

    #[ORM\Column(type: 'integer')]
    private int $updatedCount;

    #[ORM\Column(type: 'integer')]
    private int $unchangedCount;

    #[ORM\Column(type: 'integer')]
    private int $ignoredCount;

    #[ORM\Column(type: 'integer')]
    private int $duplicateCount;

    #[ORM\Column(type: 'integer')]
    private int $invalidEmailCount;

    #[ORM\Column(type: 'integer')]
    private int $missingGroupCount;

    /**
     * @var list<array{source_group: string, target_group: ?string, rows: int, ignored: bool}>
     */
    #[ORM\Column(type: Types::JSON)]
    private array $groupSummary;

    /**
     * @param list<array{source_group: string, target_group: ?string, rows: int, ignored: bool}> $groupSummary
     */
    public function __construct(
        string $originalFilename,
        string $storedFilename,
        ?string $contentType,
        int $fileSize,
        int $totalRows,
        int $createdCount,
        int $updatedCount,
        int $unchangedCount,
        int $ignoredCount,
        int $duplicateCount,
        int $invalidEmailCount,
        int $missingGroupCount,
        array $groupSummary,
    ) {
        $this->id = Uuid::uuid4();
        $this->originalFilename = $originalFilename;
        $this->storedFilename = $storedFilename;
        $this->contentType = $contentType;
        $this->fileSize = $fileSize;
        $this->totalRows = $totalRows;
        $this->createdCount = $createdCount;
        $this->updatedCount = $updatedCount;
        $this->unchangedCount = $unchangedCount;
        $this->ignoredCount = $ignoredCount;
        $this->duplicateCount = $duplicateCount;
        $this->invalidEmailCount = $invalidEmailCount;
        $this->missingGroupCount = $missingGroupCount;
        $this->groupSummary = $groupSummary;
    }

    public function getId(): UuidInterface
    {
        return $this->id;
    }

    public function getOriginalFilename(): string
    {
        return $this->originalFilename;
    }

    public function getStoredFilename(): string
    {
        return $this->storedFilename;
    }

    public function getContentType(): ?string
    {
        return $this->contentType;
    }

    public function getFileSize(): int
    {
        return $this->fileSize;
    }

    public function getTotalRows(): int
    {
        return $this->totalRows;
    }

    public function getCreatedCount(): int
    {
        return $this->createdCount;
    }

    public function getUpdatedCount(): int
    {
        return $this->updatedCount;
    }

    public function getUnchangedCount(): int
    {
        return $this->unchangedCount;
    }

    public function getIgnoredCount(): int
    {
        return $this->ignoredCount;
    }

    public function getDuplicateCount(): int
    {
        return $this->duplicateCount;
    }

    public function getInvalidEmailCount(): int
    {
        return $this->invalidEmailCount;
    }

    public function getMissingGroupCount(): int
    {
        return $this->missingGroupCount;
    }

    /**
     * @return list<array{source_group: string, target_group: ?string, rows: int, ignored: bool}>
     */
    public function getGroupSummary(): array
    {
        return $this->groupSummary;
    }
}
