<?php

namespace App\Entity;

use App\Repository\SargassumObservationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: SargassumObservationRepository::class)]
#[ORM\Index(columns: ['detected_at'], name: 'idx_observation_detected_at')]
#[ORM\Index(columns: ['source'], name: 'idx_observation_source')]
class SargassumObservation
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;

    #[ORM\Column(type: 'geometry', options: ['geometry_type' => 'MULTIPOLYGON', 'srid' => 4326])]
    private mixed $geometry = null;

    #[ORM\Column(type: 'geometry', nullable: true, options: ['geometry_type' => 'POLYGON', 'srid' => 4326])]
    private mixed $bbox = null;

    #[ORM\Column]
    private \DateTimeImmutable $detectedAt;

    #[ORM\Column(length: 50)]
    private string $source;

    #[ORM\Column(length: 100)]
    private string $tileId;

    #[ORM\Column]
    private float $cloudCoverage;

    #[ORM\Column]
    private float $confidence;

    #[ORM\Column]
    private float $afaiMean;

    #[ORM\Column]
    private float $afaiStd;

    #[ORM\Column(nullable: true)]
    private ?float $coverageArea = null;

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

    #[ORM\Column]
    private \DateTimeImmutable $createdAt;

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

    public function __construct()
    {
        $this->detectedAt    = new \DateTimeImmutable();
        $this->source        = '';
        $this->tileId        = '';
        $this->cloudCoverage = 0.0;
        $this->confidence    = 0.0;
        $this->afaiMean      = 0.0;
        $this->afaiStd       = 0.0;
        $this->createdAt     = new \DateTimeImmutable();
        $this->forecasts     = new ArrayCollection();
    }

    public function getId(): ?Uuid { return $this->id; }
    public function getGeometry(): mixed { return $this->geometry; }
    public function setGeometry(mixed $geometry): static { $this->geometry = $geometry; return $this; }
    public function getBbox(): mixed { return $this->bbox; }
    public function setBbox(mixed $bbox): static { $this->bbox = $bbox; return $this; }
    public function getDetectedAt(): \DateTimeImmutable { return $this->detectedAt; }
    public function setDetectedAt(\DateTimeImmutable $detectedAt): static { $this->detectedAt = $detectedAt; return $this; }
    public function getSource(): string { return $this->source; }
    public function setSource(string $source): static { $this->source = $source; return $this; }
    public function getTileId(): string { return $this->tileId; }
    public function setTileId(string $tileId): static { $this->tileId = $tileId; return $this; }
    public function getCloudCoverage(): float { return $this->cloudCoverage; }
    public function setCloudCoverage(float $cloudCoverage): static { $this->cloudCoverage = $cloudCoverage; return $this; }
    public function getConfidence(): float { return $this->confidence; }
    public function setConfidence(float $confidence): static { $this->confidence = $confidence; return $this; }
    public function getAfaiMean(): float { return $this->afaiMean; }
    public function setAfaiMean(float $afaiMean): static { $this->afaiMean = $afaiMean; return $this; }
    public function getAfaiStd(): float { return $this->afaiStd; }
    public function setAfaiStd(float $afaiStd): static { $this->afaiStd = $afaiStd; return $this; }
    public function getCoverageArea(): ?float { return $this->coverageArea; }
    public function setCoverageArea(?float $coverageArea): static { $this->coverageArea = $coverageArea; return $this; }
    public function getProcessingVersion(): ?string { return $this->processingVersion; }
    public function setProcessingVersion(?string $processingVersion): static { $this->processingVersion = $processingVersion; return $this; }
    public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }

    /** @return Collection<int, SargassumForecast> */
    public function getForecasts(): Collection { return $this->forecasts; }
}
