<?php

namespace App\Entity;

use App\Repository\RemoteCalendarRuleRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: RemoteCalendarRuleRepository::class)]
class RemoteCalendarRule extends AbstractEntity
{
    #[ORM\ManyToOne(inversedBy: 'rules')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ?RemoteCalendar $remoteCalendar = null;

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

    #[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $busyFromHour = null;

    #[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $busyToHour = null;

    #[ORM\Column]
    private ?bool $isRemoteAvailable = null;

    #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $availableFromDate = null;

    #[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
    private ?\DateTimeInterface $availableToDate = null;

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

    public function getBusyWeekdays(): array
    {
        return $this->busyWeekdays;
    }

    public function setBusyWeekdays(?array $busyWeekdays): static
    {
        $this->busyWeekdays = $busyWeekdays;

        return $this;
    }

    public function getBusyFromHour(): string
    {
        return $this->busyFromHour->format('H:i');
    }

    /**
     * @throws \Exception
     */
    public function setBusyFromHour(?string $busyFromHour): static
    {
        $this->busyFromHour = new \DateTimeImmutable($busyFromHour);

        return $this;
    }

    public function getBusyToHour(): string
    {
        return $this->busyToHour->format('H:i');
    }

    /**
     * @throws \Exception
     */
    public function setBusyToHour(?string $busyToHour): static
    {
        $this->busyToHour = new \DateTimeImmutable($busyToHour);

        return $this;
    }

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

    public function setRemoteAvailable(bool $isRemoteAvailable): static
    {
        $this->isRemoteAvailable = $isRemoteAvailable;

        return $this;
    }

    public function getAvailableFromDate(): ?\DateTimeInterface
    {
        return $this->availableFromDate;
    }

    public function setAvailableFromDate(?\DateTimeInterface $availableFromDate): static
    {
        $this->availableFromDate = $availableFromDate;

        return $this;
    }

    public function getAvailableToDate(): ?\DateTimeInterface
    {
        return $this->availableToDate;
    }

    public function setAvailableToDate(?\DateTimeInterface $availableToDate): static
    {
        $this->availableToDate = $availableToDate;

        return $this;
    }

    public function getAvailableReason(): ?string
    {
        return $this->availableReason;
    }

    public function setAvailableReason(?string $availableReason): static
    {
        $this->availableReason = $availableReason;

        return $this;
    }

    public function getRemoteCalendar(): ?RemoteCalendar
    {
        return $this->remoteCalendar;
    }

    public function setRemoteCalendar(?RemoteCalendar $remoteCalendar): static
    {
        $this->remoteCalendar = $remoteCalendar;

        return $this;
    }
}
