<?php

namespace App\Entity;

use App\Repository\BroadcastRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: BroadcastRepository::class)]
#[ORM\Table(name: '`broadcast`')]
class Broadcast
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column]
    private ?float $cost = null;

    #[ORM\Column(type: Types::DATE_MUTABLE)]
    private ?\DateTime $date_start = null;

    #[ORM\Column(type: Types::DATE_MUTABLE)]
    private ?\DateTime $date_end = null;

    #[ORM\Column]
    private ?\DateTime $date_create = null;

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

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

    #[ORM\ManyToOne(inversedBy: 'broadcasts')]
    private ?User $create_by = null;

    #[ORM\ManyToOne(inversedBy: 'broadcasts')]
    #[ORM\JoinColumn(nullable: false)]
    private ?Investigation $investigation = null;

    /**
     * @var Collection<int, State>
     */
    #[ORM\OneToMany(targetEntity: State::class, mappedBy: 'broadcast')]
    private Collection $states;

    #[ORM\Column(type: Types::SMALLINT)]
    private ?int $last_state = null;

    public function __construct()
    {
        $this->date_create = new \DateTime();
        $this->notification_sms = false;
        $this->notification_email = false;
        $this->last_state = 31;
        $this->states = new ArrayCollection();
    }

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

    public function getCost(): ?float
    {
        return $this->cost;
    }

    public function setCost(float $cost): static
    {
        $this->cost = $cost;

        return $this;
    }

    public function getDateStart(): ?\DateTime
    {
        return $this->date_start;
    }

    public function setDateStart(\DateTime $date_start): static
    {
        $this->date_start = $date_start;

        return $this;
    }

    public function getDateEnd(): ?\DateTime
    {
        return $this->date_end;
    }

    public function setDateEnd(\DateTime $date_end): static
    {
        $this->date_end = $date_end;

        return $this;
    }

    public function getDateCreate(): ?\DateTime
    {
        return $this->date_create;
    }

    public function setDateCreate(\DateTime $date_create): static
    {
        $this->date_create = $date_create;

        return $this;
    }

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

    public function setNotificationSms(bool $notification_sms): static
    {
        $this->notification_sms = $notification_sms;

        return $this;
    }

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

    public function setNotificationEmail(bool $notification_email): static
    {
        $this->notification_email = $notification_email;

        return $this;
    }

    public function getCreateBy(): ?User
    {
        return $this->create_by;
    }

    public function setCreateBy(?User $create_by): static
    {
        $this->create_by = $create_by;

        return $this;
    }

    public function getInvestigation(): ?Investigation
    {
        return $this->investigation;
    }

    public function setInvestigation(?Investigation $investigation): static
    {
        $this->investigation = $investigation;

        return $this;
    }

    /**
     * @return Collection<int, State>
     */
    public function getStates(): Collection
    {
        return $this->states;
    }

    public function addState(State $state): static
    {
        if (!$this->states->contains($state)) {
            $this->states->add($state);
            $state->setBroadcast($this);
        }

        return $this;
    }

    public function removeState(State $state): static
    {
        if ($this->states->removeElement($state)) {
            // set the owning side to null (unless already changed)
            if ($state->getBroadcast() === $this) {
                $state->setBroadcast(null);
            }
        }

        return $this;
    }

    public function getLastState(): ?int
    {
        return $this->last_state;
    }

    public function setLastState(int $last_state): static
    {
        $this->last_state = $last_state;

        return $this;
    }
}
