<?php

declare(strict_types=1);

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;

#[ApiResource(
    operations: [
        new GetCollection(
            security: "is_granted('ROLE_USER')"
        ),
        new Get(
            security: "is_granted('ROLE_USER')"
        ),
        new Post(
            security: "is_granted('ROLE_ADMIN')"
        ),
        new Patch(
            security: "is_granted('ROLE_ADMIN')"
        ),
        new Delete(
            security: "is_granted('ROLE_ADMIN')"
        ),
    ],
    normalizationContext: ['groups' => ['absence_type:read']],
    paginationEnabled: false,
)]
#[ORM\Entity]
#[ORM\Table(name: 'absence_types')]
class AbsenceType
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    #[Groups(['absence:read', 'absence_type:read'])]
    private ?int $id = null;

    #[ORM\Column(type: 'string', length: 10)]
    #[Groups(['absence:read', 'absence_type:read'])]
    private string $code = '';

    #[ORM\Column(type: 'string', length: 100)]
    #[Groups(['absence:read', 'absence_type:read'])]
    private string $label = '';

    #[ORM\Column(type: 'string', length: 20)]
    #[Groups(['absence:read', 'absence_type:read'])]
    private string $color = '';

    #[ORM\Column(type: 'boolean', options: ['default' => false])]
    #[Groups(['absence:read', 'absence_type:read'])]
    private bool $countAsWorkedHours = false;

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

    public function getCode(): string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

    public function getLabel(): string
    {
        return $this->label;
    }

    public function setLabel(string $label): self
    {
        $this->label = $label;

        return $this;
    }

    public function getColor(): string
    {
        return $this->color;
    }

    public function setColor(string $color): self
    {
        $this->color = $color;

        return $this;
    }

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

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

    public function setCountAsWorkedHours(bool $countAsWorkedHours): self
    {
        $this->countAsWorkedHours = $countAsWorkedHours;

        return $this;
    }
}
