<?php

declare(strict_types=1);

namespace App\Entity\Tenant;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'news_agency_configs')]
#[ORM\HasLifecycleCallbacks]
class NewsAgencyConfig
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: Types::INTEGER)]
    private ?int $id = null;

    #[ORM\Column(type: Types::STRING, length: 50, unique: true)]
    private string $agencySlug;

    #[ORM\Column(type: Types::STRING, length: 100)]
    private string $agencyName;

    #[ORM\Column(type: Types::STRING, length: 500, nullable: true)]
    private ?string $apiUrl = null;

    #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
    private ?string $apiKey = null;

    #[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
    private ?string $apiSecret = null;

    #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
    private bool $isActive = false;

    #[ORM\Column(type: Types::BOOLEAN, options: ['default' => false])]
    private bool $autoPublish = false;

    #[ORM\Column(type: Types::INTEGER, nullable: true)]
    private ?int $defaultCategoryId = null;

    #[ORM\Column(type: Types::INTEGER, options: ['default' => 15])]
    private int $fetchInterval = 15;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
    private ?\DateTimeImmutable $lastFetchedAt = null;

    #[ORM\Column(type: Types::JSON, nullable: true)]
    private ?array $config = null;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private \DateTimeImmutable $createdAt;

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

    public function getAgencySlug(): string
    {
        return $this->agencySlug;
    }

    public function setAgencySlug(string $agencySlug): self
    {
        $this->agencySlug = $agencySlug;

        return $this;
    }

    public function getAgencyName(): string
    {
        return $this->agencyName;
    }

    public function setAgencyName(string $agencyName): self
    {
        $this->agencyName = $agencyName;

        return $this;
    }

    public function getApiUrl(): ?string
    {
        return $this->apiUrl;
    }

    public function setApiUrl(?string $apiUrl): self
    {
        $this->apiUrl = $apiUrl;

        return $this;
    }

    public function getApiKey(): ?string
    {
        return $this->apiKey;
    }

    public function setApiKey(?string $apiKey): self
    {
        $this->apiKey = $apiKey;

        return $this;
    }

    public function getApiSecret(): ?string
    {
        return $this->apiSecret;
    }

    public function setApiSecret(?string $apiSecret): self
    {
        $this->apiSecret = $apiSecret;

        return $this;
    }

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

    public function setIsActive(bool $isActive): self
    {
        $this->isActive = $isActive;

        return $this;
    }

    public function isAutoPublish(): bool
    {
        return $this->autoPublish;
    }

    public function setAutoPublish(bool $autoPublish): self
    {
        $this->autoPublish = $autoPublish;

        return $this;
    }

    public function getDefaultCategoryId(): ?int
    {
        return $this->defaultCategoryId;
    }

    public function setDefaultCategoryId(?int $defaultCategoryId): self
    {
        $this->defaultCategoryId = $defaultCategoryId;

        return $this;
    }

    public function getFetchInterval(): int
    {
        return $this->fetchInterval;
    }

    public function setFetchInterval(int $fetchInterval): self
    {
        $this->fetchInterval = $fetchInterval;

        return $this;
    }

    public function getLastFetchedAt(): ?\DateTimeImmutable
    {
        return $this->lastFetchedAt;
    }

    public function setLastFetchedAt(?\DateTimeImmutable $lastFetchedAt): self
    {
        $this->lastFetchedAt = $lastFetchedAt;

        return $this;
    }

    public function getConfig(): ?array
    {
        return $this->config;
    }

    public function setConfig(?array $config): self
    {
        $this->config = $config;

        return $this;
    }

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

    #[ORM\PrePersist]
    public function onPrePersist(): void
    {
        $this->createdAt = new \DateTimeImmutable();
    }
}
