<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Index(columns: ['customer_id'], name: 'idx_action_log_customer')]
#[ORM\Index(columns: ['action'], name: 'idx_action_log_action')]
#[ORM\Index(columns: ['created_at'], name: 'idx_action_log_created')]
class ActionLog
{
    public const ACTION_SUSPEND_CUSTOMER = 'suspend_customer';
    public const ACTION_UNSUSPEND_CUSTOMER = 'unsuspend_customer';
    public const ACTION_SUSPEND_WEBSITE = 'suspend_website';
    public const ACTION_UNSUSPEND_WEBSITE = 'unsuspend_website';
    public const ACTION_SUSPEND_DOMAIN_EMAIL = 'suspend_domain_email';
    public const ACTION_UNSUSPEND_DOMAIN_EMAIL = 'unsuspend_domain_email';
    public const ACTION_DISABLE_CUSTOMER = 'disable_customer';
    public const ACTION_DELETE_CUSTOMER_DATA = 'delete_customer_data';
    public const ACTION_FORMAL_NOTICE = 'formal_notice';
    public const ACTION_TERMINATION = 'termination';

    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 50)]
    private string $action;

    #[ORM\ManyToOne(targetEntity: Customer::class)]
    #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
    private ?Customer $customer = null;

    #[ORM\Column(nullable: true)]
    private ?int $entityId = null;

    #[ORM\Column(length: 50, nullable: true)]
    private ?string $entityType = null;

    #[ORM\Column(type: 'text')]
    private string $message;

    #[ORM\Column(type: 'text', nullable: true)]
    private ?string $context = null;

    #[ORM\Column(length: 20)]
    private string $severity;

    #[ORM\Column(length: 50, nullable: true)]
    private ?string $previousState = null;

    #[ORM\Column(length: 50, nullable: true)]
    private ?string $newState = null;

    #[ORM\Column]
    private bool $success;

    #[ORM\Column(type: 'text', nullable: true)]
    private ?string $errorMessage = null;

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

    public function __construct(
        string $action,
        string $message,
        string $severity = 'info',
        bool $success = true,
    ) {
        $this->action = $action;
        $this->message = $message;
        $this->severity = $severity;
        $this->success = $success;
        $this->createdAt = new \DateTimeImmutable();
    }

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

    public function getAction(): string
    {
        return $this->action;
    }

    public function getCustomer(): ?Customer
    {
        return $this->customer;
    }

    public function setCustomer(?Customer $customer): static
    {
        $this->customer = $customer;

        return $this;
    }

    public function getEntityId(): ?int
    {
        return $this->entityId;
    }

    public function setEntityId(?int $entityId): static
    {
        $this->entityId = $entityId;

        return $this;
    }

    public function getEntityType(): ?string
    {
        return $this->entityType;
    }

    public function setEntityType(?string $entityType): static
    {
        $this->entityType = $entityType;

        return $this;
    }

    public function getMessage(): string
    {
        return $this->message;
    }

    public function getContext(): ?string
    {
        return $this->context;
    }

    public function setContext(?string $context): static
    {
        $this->context = $context;

        return $this;
    }

    public function getSeverity(): string
    {
        return $this->severity;
    }

    public function getPreviousState(): ?string
    {
        return $this->previousState;
    }

    public function setPreviousState(?string $previousState): static
    {
        $this->previousState = $previousState;

        return $this;
    }

    public function getNewState(): ?string
    {
        return $this->newState;
    }

    public function setNewState(?string $newState): static
    {
        $this->newState = $newState;

        return $this;
    }

    public function isSuccess(): bool
    {
        return $this->success;
    }

    public function getErrorMessage(): ?string
    {
        return $this->errorMessage;
    }

    public function setErrorMessage(?string $errorMessage): static
    {
        $this->errorMessage = $errorMessage;
        $this->success = false;

        return $this;
    }

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