<?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: 'settings')]
class Setting
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: Types::INTEGER)]
    private ?int $id = null;

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

    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $settingValue = null;

    #[ORM\Column(type: Types::STRING, length: 50, options: ['default' => 'general'])]
    private string $settingGroup = 'general';

    #[ORM\Column(type: Types::STRING, length: 20, options: ['default' => 'text'])]
    private string $settingType = 'text';

    private const VALID_SETTING_TYPES = ['text', 'textarea', 'boolean', 'number', 'json', 'image'];

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

    public function getSettingKey(): string
    {
        return $this->settingKey;
    }

    public function setSettingKey(string $settingKey): self
    {
        $this->settingKey = $settingKey;

        return $this;
    }

    public function getSettingValue(): ?string
    {
        return $this->settingValue;
    }

    public function setSettingValue(?string $settingValue): self
    {
        $this->settingValue = $settingValue;

        return $this;
    }

    public function getSettingGroup(): string
    {
        return $this->settingGroup;
    }

    public function setSettingGroup(string $settingGroup): self
    {
        $this->settingGroup = $settingGroup;

        return $this;
    }

    public function getSettingType(): string
    {
        return $this->settingType;
    }

    public function setSettingType(string $settingType): self
    {
        if (!in_array($settingType, self::VALID_SETTING_TYPES, true)) {
            throw new \InvalidArgumentException(
                sprintf('Invalid setting type "%s". Allowed: %s', $settingType, implode(', ', self::VALID_SETTING_TYPES))
            );
        }

        $this->settingType = $settingType;

        return $this;
    }
}
