<?php
namespace App\Entity;
use App\Repository\SeasonGoogleChatConfigRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: SeasonGoogleChatConfigRepository::class)]
class SeasonGoogleChatConfig
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\OneToOne(inversedBy: 'googleChatConfig', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Season $season = null;
#[ORM\Column(length: 500, nullable: true)]
private ?string $webhookUrl = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $spaceName = null;
#[ORM\Column]
private ?bool $isEnabled = false;
#[ORM\Column(length: 50)]
private ?string $timezone = 'America/New_York';
#[ORM\OneToMany(mappedBy: 'googleChatConfig', targetEntity: SeasonGoogleChatMessageType::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $messageTypes;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $createdAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updatedAt = null;
public function __construct()
{
$this->messageTypes = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
}
public function __toString(): string
{
return $this->season?->getName() . ' - Google Chat Config' ?? 'Google Chat Config';
}
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getSeason(): ?Season
{
return $this->season;
}
public function setSeason(Season $season): static
{
$this->season = $season;
return $this;
}
public function getWebhookUrl(): ?string
{
return $this->webhookUrl;
}
public function setWebhookUrl(?string $webhookUrl): static
{
$this->webhookUrl = $webhookUrl;
return $this;
}
public function getSpaceName(): ?string
{
return $this->spaceName;
}
public function setSpaceName(?string $spaceName): static
{
$this->spaceName = $spaceName;
return $this;
}
public function isIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(bool $isEnabled): static
{
$this->isEnabled = $isEnabled;
return $this;
}
public function getTimezone(): ?string
{
return $this->timezone;
}
public function setTimezone(string $timezone): static
{
$this->timezone = $timezone;
return $this;
}
/**
* @return Collection<int, SeasonGoogleChatMessageType>
*/
public function getMessageTypes(): Collection
{
return $this->messageTypes;
}
public function addMessageType(SeasonGoogleChatMessageType $messageType): static
{
if (!$this->messageTypes->contains($messageType)) {
$this->messageTypes->add($messageType);
$messageType->setGoogleChatConfig($this);
}
return $this;
}
public function removeMessageType(SeasonGoogleChatMessageType $messageType): static
{
if ($this->messageTypes->removeElement($messageType)) {
// set the owning side to null (unless already changed)
if ($messageType->getGoogleChatConfig() === $this) {
$messageType->setGoogleChatConfig(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Check if a specific message type is enabled
*/
public function isMessageTypeEnabled(string $messageType): bool
{
foreach ($this->messageTypes as $type) {
if ($type->getMessageType() === $messageType && $type->isIsEnabled()) {
return true;
}
}
return false;
}
/**
* Get message type configuration
*/
public function getMessageTypeConfig(string $messageType): ?SeasonGoogleChatMessageType
{
foreach ($this->messageTypes as $type) {
if ($type->getMessageType() === $messageType) {
return $type;
}
}
return null;
}
}