<?php

namespace App\Insurance\Entity;

use App\Insurance\Enum\InsuranceType;
use App\Insurance\Repository\InsuranceRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: InsuranceRepository::class)]
#[ORM\Table(name: 'insurances')]
#[ORM\Index(columns: ['type'], name: 'idx_insurances_type')]
#[ORM\Index(columns: ['status'], name: 'idx_insurances_status')]
class Insurance
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 36, unique: true)]
    private string $uuid;

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

    #[ORM\Column(type: 'string', length: 20, enumType: InsuranceType::class)]
    private InsuranceType $type;

    #[ORM\Column(name: 'logo_url', type: 'string', length: 500, nullable: true)]
    private ?string $logoUrl = null;

    #[ORM\Column(type: 'smallint')]
    private int $status = 1;

    public function __construct(string $name, InsuranceType $type)
    {
        $this->uuid = Uuid::v4()->toRfc4122();
        $this->name = $name;
        $this->type = $type;
    }

    public function getId(): ?int         { return $this->id; }
    public function getUuid(): string     { return $this->uuid; }
    public function getName(): string     { return $this->name; }
    public function getType(): InsuranceType { return $this->type; }
    public function getLogoUrl(): ?string { return $this->logoUrl; }
    public function getStatus(): int      { return $this->status; }

    public function setName(string $v): self          { $this->name = $v; return $this; }
    public function setType(InsuranceType $v): self   { $this->type = $v; return $this; }
    public function setLogoUrl(?string $v): self      { $this->logoUrl = $v; return $this; }
    public function setStatus(int $v): self           { $this->status = $v; return $this; }

    public function toArray(): array
    {
        return [
            'id'       => $this->id,
            'uuid'     => $this->uuid,
            'name'     => $this->name,
            'type'     => $this->type->value,
            'logo_url' => $this->logoUrl,
            'status'   => $this->status,
        ];
    }
}
