<?php

namespace App\Entity;

use App\Repository\SargassumForecastRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: SargassumForecastRepository::class)]
#[ORM\Index(columns: ['valid_at'], name: 'idx_forecast_valid_at')]
#[ORM\Index(columns: ['time_horizon'], name: 'idx_forecast_horizon')]
// Routes gérées par ForecastController (filtres bbox + horizon)
class SargassumForecast
{
    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;

    #[ORM\ManyToOne(inversedBy: 'forecasts')]
    #[ORM\JoinColumn(nullable: false)]
    private SargassumObservation $sourceObservation;

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

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

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

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

    #[ORM\Column]
    private int $timeHorizon;

    #[ORM\Column]
    private float $confidence;

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

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

    public function __construct()
    {
        $this->validAt       = new \DateTimeImmutable();
        $this->computedAt    = new \DateTimeImmutable();
        $this->createdAt     = new \DateTimeImmutable();
        $this->modelVersion  = '';
        $this->timeHorizon   = 0;
        $this->confidence    = 0.0;
    }

    public function getId(): ?Uuid { return $this->id; }
    public function getSourceObservation(): SargassumObservation { return $this->sourceObservation; }
    public function setSourceObservation(SargassumObservation $sourceObservation): static { $this->sourceObservation = $sourceObservation; return $this; }
    public function getGeometry(): mixed { return $this->geometry; }
    public function setGeometry(mixed $geometry): static { $this->geometry = $geometry; return $this; }
    public function getValidAt(): \DateTimeImmutable { return $this->validAt; }
    public function setValidAt(\DateTimeImmutable $validAt): static { $this->validAt = $validAt; return $this; }
    public function getComputedAt(): \DateTimeImmutable { return $this->computedAt; }
    public function setComputedAt(\DateTimeImmutable $computedAt): static { $this->computedAt = $computedAt; return $this; }
    public function getModelVersion(): string { return $this->modelVersion; }
    public function setModelVersion(string $modelVersion): static { $this->modelVersion = $modelVersion; return $this; }
    public function getTimeHorizon(): int { return $this->timeHorizon; }
    public function setTimeHorizon(int $timeHorizon): static { $this->timeHorizon = $timeHorizon; return $this; }
    public function getConfidence(): float { return $this->confidence; }
    public function setConfidence(float $confidence): static { $this->confidence = $confidence; return $this; }
    public function getDriftVectorAvg(): mixed { return $this->driftVectorAvg; }
    public function setDriftVectorAvg(mixed $driftVectorAvg): static { $this->driftVectorAvg = $driftVectorAvg; return $this; }
    public function getCreatedAt(): \DateTimeImmutable { return $this->createdAt; }
}
