<?php

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\ImpactScoreRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;

#[ORM\Entity(repositoryClass: ImpactScoreRepository::class)]
#[ORM\Index(columns: ['timestamp'], name: 'idx_score_timestamp')]
#[ORM\Index(columns: ['level'], name: 'idx_score_level')]
#[ApiResource(
    operations: [
        new GetCollection(),
        new Get(),
    ]
)]
class ImpactScore
{
    #[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: 'impactScores')]
    #[ORM\JoinColumn(nullable: false)]
    private CoastalPoint $coastalPoint;

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

    #[ORM\Column]
    private int $score;

    #[ORM\Column(length: 20)]
    private string $level;

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

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

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

    /**
     * Horizon (en heures) auquel les sargasses devraient atteindre le spot.
     * 0 = impact en cours, null = aucun impact prévu dans les 48h.
     */
    #[ORM\Column(nullable: true)]
    private ?int $etaHours = null;

    public function __construct()
    {
        $this->timestamp = new \DateTimeImmutable();
        $this->score = 0;
        $this->level = 'low';
    }

    public function getId(): ?Uuid { return $this->id; }
    public function getCoastalPoint(): CoastalPoint { return $this->coastalPoint; }
    public function setCoastalPoint(CoastalPoint $coastalPoint): static { $this->coastalPoint = $coastalPoint; return $this; }
    public function getTimestamp(): \DateTimeImmutable { return $this->timestamp; }
    public function setTimestamp(\DateTimeImmutable $timestamp): static { $this->timestamp = $timestamp; return $this; }
    public function getScore(): int { return $this->score; }
    public function setScore(int $score): static { $this->score = $score; return $this; }
    public function getLevel(): string { return $this->level; }
    public function setLevel(string $level): static { $this->level = $level; return $this; }
    public function getDistanceToNearestSargassum(): ?float { return $this->distanceToNearestSargassum; }
    public function setDistanceToNearestSargassum(?float $d): static { $this->distanceToNearestSargassum = $d; return $this; }
    public function getDensityEstimate(): ?float { return $this->densityEstimate; }
    public function setDensityEstimate(?float $d): static { $this->densityEstimate = $d; return $this; }
    public function getTrend(): ?string { return $this->trend; }
    public function setTrend(?string $trend): static { $this->trend = $trend; return $this; }
    public function getEtaHours(): ?int { return $this->etaHours; }
    public function setEtaHours(?int $etaHours): static { $this->etaHours = $etaHours; return $this; }
}
