<?php

/**
 * Copyright (c) 2026 PrestaShop SA
 *
 * This file is part of the PrestaShop AskAI solution.
 * For license terms, see LICENSE.md in this module.
 */

declare(strict_types=1);

namespace PrestaShop\Module\PsAskAi\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table()
 *
 * @ORM\Entity(repositoryClass="PrestaShop\Module\PsAskAi\Repository\PsAskAiConversationRepository")
 *
 * @ORM\HasLifecycleCallbacks
 */
class PsAskAiConversation
{
    /**
     * @ORM\Id
     *
     * @ORM\Column(name="id_conversation", type="integer")
     *
     * @ORM\GeneratedValue(strategy="AUTO")
     *
     * @phpstan-ignore property.unusedType
     */
    private ?int $id = null;

    /**
     * @ORM\Column(name="thread_id", type="string", length=64, unique=true)
     */
    private string $threadId;

    /**
     * @ORM\Column(name="id_employee", type="integer")
     */
    private int $idEmployee;

    /**
     * @ORM\Column(name="id_shop", type="integer")
     */
    private int $idShop;

    /**
     * @ORM\Column(name="title", type="string", length=255, nullable=true)
     */
    private ?string $title = null;

    /**
     * @ORM\Column(name="created_at", type="datetime")
     */
    private \DateTimeInterface $createdAt;

    /**
     * @ORM\Column(name="updated_at", type="datetime")
     */
    private \DateTimeInterface $updatedAt;

    /**
     * @ORM\Column(name="archived_at", type="datetime", nullable=true)
     */
    private ?\DateTimeInterface $archivedAt = null;

    public function __construct(string $threadId, int $idEmployee, int $idShop, ?string $title = null)
    {
        $this->threadId = $threadId;
        $this->idEmployee = $idEmployee;
        $this->idShop = $idShop;
        $this->title = $title;
        $now = new \DateTimeImmutable();
        $this->createdAt = $now;
        $this->updatedAt = $now;
    }

    /**
     * @ORM\PreUpdate
     */
    public function onUpdate(): void
    {
        $this->updatedAt = new \DateTimeImmutable();
    }

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

    public function getThreadId(): string
    {
        return $this->threadId;
    }

    public function getIdEmployee(): int
    {
        return $this->idEmployee;
    }

    public function getIdShop(): int
    {
        return $this->idShop;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(?string $title): self
    {
        $this->title = $title;

        return $this;
    }

    public function getCreatedAt(): \DateTimeInterface
    {
        return $this->createdAt;
    }

    public function getUpdatedAt(): \DateTimeInterface
    {
        return $this->updatedAt;
    }

    public function touch(): self
    {
        $this->updatedAt = new \DateTimeImmutable();

        return $this;
    }

    public function getArchivedAt(): ?\DateTimeInterface
    {
        return $this->archivedAt;
    }

    public function archive(): self
    {
        $this->archivedAt = new \DateTimeImmutable();

        return $this;
    }
}
