<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Uid\Uuid;
use App\Entity\Person\Person;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
#[ORM\Entity]
#[ORM\Table(name: 'world')]
#[ORM\HasLifecycleCallbacks]
class World
{
#[ORM\Id]
#[ORM\Column(type: 'uuid', unique: true)]
private $id;
#[ORM\Column(type: 'json', nullable: false)]
private array $promts = [];
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $isBase = false;
#[ORM\Column(type: 'uuid', nullable: true)]
private ?string $defaultLocationId = null;
#[ORM\Column(type: 'string', nullable: false)]
private ?string $name;
#[ORM\Column(name: 'save_version', type: 'integer', nullable: false, options: ['default' => 1])]
private int $saveVersion = 1;
#[ORM\Column(type: 'text', nullable: false, options: ['default' => ''])]
private string $description = '';
#[ORM\Column(type: 'string', nullable: true)]
private ?string $background = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $isPublic = false;
#[ORM\Column(type: 'jsonb', nullable: true)]
private ?array $settings = [];
#[ORM\Column(type: 'datetime', nullable: false)]
private \DateTimeInterface $createdDate;
#[ORM\Column(type: 'datetime', nullable: false)]
private \DateTimeInterface $editedDate;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?\DateTimeInterface $publishedDate = null;
#[ORM\Column(type: 'uuid', nullable: true)]
private ?string $createdBy = null;
#[ORM\Column(type: 'jsonb', nullable: true)]
private ?array $badges = [];
#[ORM\OneToMany(mappedBy: 'world', targetEntity: Person::class)]
private Collection $persons;
#[ORM\OneToMany(mappedBy: 'world', targetEntity: Location\Location::class)]
private Collection $locations;
public function __construct()
{
$this->id = Uuid::v4();
$this->persons = new ArrayCollection();
$this->locations = new ArrayCollection();
}
#[ORM\PrePersist]
public function setCreatedDate(): void
{
$this->createdDate = new \DateTime();
$this->editedDate = new \DateTime();
}
#[ORM\PreUpdate]
public function setEditedDate(): void
{
$this->editedDate = new \DateTime();
}
public function getSettings(): ?array
{
return $this->settings;
}
public function setSettings(?array $settings): void
{
$this->settings = $settings;
}
public function getCreatedDate(): \DateTimeInterface
{
return $this->createdDate;
}
public function getEditedDate(): \DateTimeInterface
{
return $this->editedDate;
}
public function getPublishedDate(): ?\DateTimeInterface
{
return $this->publishedDate;
}
public function setPublishedDate(?\DateTimeInterface $publishedDate): void
{
$this->publishedDate = $publishedDate;
}
public function getCreatedBy(): ?string
{
return $this->createdBy;
}
public function setCreatedBy(?string $createdBy): void
{
$this->createdBy = $createdBy;
}
public function getBadges(): ?array
{
return $this->badges;
}
public function setBadges(?array $badges): void
{
$this->badges = $badges;
}
public function getSaveVersion(): int
{
return $this->saveVersion;
}
public function setSaveVersion(int $saveVersion): void
{
$this->saveVersion = $saveVersion;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description): void
{
$this->description = $description;
}
public function getBackground(): ?string
{
return $this->background;
}
public function setBackground(?string $background): void
{
$this->background = $background;
}
public function isPublic(): bool
{
return $this->isPublic;
}
public function setIsPublic(bool $isPublic): void
{
$this->isPublic = $isPublic;
}
// Getters and setters
public function getId()
{
return $this->id;
}
public function getPromts(): array
{
return $this->promts;
}
public function setPromts(array $promts): void
{
$this->promts = $promts;
}
public function isBase(): bool
{
return $this->isBase;
}
public function setIsBase(bool $isBase): void
{
$this->isBase = $isBase;
}
public function getDefaultLocationId(): ?string
{
return $this->defaultLocationId;
}
public function setDefaultLocationId(?string $defaultLocationId): void
{
$this->defaultLocationId = $defaultLocationId;
}
/**
* @return Collection|Person[]
*/
public function getPersons(): Collection
{
return $this->persons;
}
/**
* @return Collection|Location[]
*/
public function getLocations(): Collection
{
return $this->locations;
}
public function isReadyToPub(): bool
{
if (!$this->getDefaultLocationId()) {
return false;
}
if ($this->persons->isEmpty()) {
return false;
}
if (!$this->getBackground()) {
return false;
}
return true;
}
/**
* Get public badges for the world
*
* @return array
*/
public function getPublicBadges(): array
{
$badges = [];
// Always add "Автор: openrpg" badge
$badges[] = "Автор: openrpg";
// Check for "бесплатно" badge
if ($this->settings && isset($this->settings['llm']) && strpos($this->settings['llm'], ':free') !== false) {
$badges[] = "бесплатно";
}
// Add all saved badges
if ($this->badges) {
$badges = array_merge($badges, $this->badges);
}
// Add badge based on location count
$locationCount = count($this->getLocations());
if ($locationCount < 4) {
$badges[] = "маленькое приключение";
} elseif ($locationCount <= 15) {
$badges[] = "средний";
} elseif ($locationCount <= 30) {
$badges[] = "огромное";
} else {
$badges[] = "игровая вселенная";
}
return $badges;
}
}