<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Ferienpass\CoreBundle\Repository\IntegrationCredentialRepository;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: IntegrationCredentialRepository::class)]
class IntegrationCredential
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
    private Uuid $id;

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

    #[ORM\Column(type: 'json')]
    private array $config = [];

    #[ORM\ManyToOne(targetEntity: IntegrationConfig::class, inversedBy: 'credentials')]
    #[ORM\JoinColumn(referencedColumnName: 'id', nullable: false)]
    private ?IntegrationConfig $integrationConfig = null;

    public function __construct(string $env)
    {
        $this->env = $env;
    }

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

    public function getEnv(): string
    {
        return $this->env;
    }

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

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

        return $this;
    }

    public function getIntegrationConfig(): ?IntegrationConfig
    {
        return $this->integrationConfig;
    }

    public function setIntegrationConfig(?IntegrationConfig $integrationConfig): self
    {
        $this->integrationConfig = $integrationConfig;

        return $this;
    }
}
