<?php

declare(strict_types=1);

namespace App\Entity;

use App\Repository\InscriptionParcoursRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: InscriptionParcoursRepository::class)]
#[ORM\Table(name: 'inscription_parcours')]
#[ORM\Index(name: 'IDX_INSCRIPTION_PARCOURS_ACTIVE_ORDER', columns: ['inscription_id', 'actif', 'principal', 'ordre'])]
#[ORM\HasLifecycleCallbacks]
class InscriptionParcours
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ?Ecole $ecole = null;

    #[ORM\ManyToOne(inversedBy: 'parcours')]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private ?Inscription $inscription = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?AnneeScolaire $anneeScolaire = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Section $sectionSouhaitee = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Niveau $niveauSouhaite = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Classe $classeSouhaitee = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Section $sectionFinale = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Niveau $niveauFinal = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(onDelete: 'SET NULL')]
    private ?Classe $classeFinale = null;

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

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

    #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]
    private ?string $tarifPropose = null;

    #[ORM\Column(options: ['default' => 1])]
    private int $ordre = 1;

    #[ORM\Column(options: ['default' => false])]
    private bool $principal = false;

    #[ORM\Column(options: ['default' => true])]
    private bool $actif = true;

    #[ORM\Column(type: Types::TEXT, nullable: true)]
    private ?string $observation = null;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private ?\DateTimeImmutable $createdAt = null;

    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
    private ?\DateTimeImmutable $updatedAt = null;

    public function getId(): ?int { return $this->id; }
    public function getEcole(): ?Ecole { return $this->ecole; }
    public function setEcole(?Ecole $ecole): static { $this->ecole = $ecole; return $this; }
    public function getInscription(): ?Inscription { return $this->inscription; }
    public function setInscription(?Inscription $inscription): static { $this->inscription = $inscription; return $this; }
    public function getAnneeScolaire(): ?AnneeScolaire { return $this->anneeScolaire; }
    public function setAnneeScolaire(?AnneeScolaire $anneeScolaire): static { $this->anneeScolaire = $anneeScolaire; return $this; }
    public function getSectionSouhaitee(): ?Section { return $this->sectionSouhaitee; }
    public function setSectionSouhaitee(?Section $sectionSouhaitee): static { $this->sectionSouhaitee = $sectionSouhaitee; return $this; }
    public function getNiveauSouhaite(): ?Niveau { return $this->niveauSouhaite; }
    public function setNiveauSouhaite(?Niveau $niveauSouhaite): static { $this->niveauSouhaite = $niveauSouhaite; return $this; }
    public function getClasseSouhaitee(): ?Classe { return $this->classeSouhaitee; }
    public function setClasseSouhaitee(?Classe $classeSouhaitee): static { $this->classeSouhaitee = $classeSouhaitee; return $this; }
    public function getSectionFinale(): ?Section { return $this->sectionFinale; }
    public function setSectionFinale(?Section $sectionFinale): static { $this->sectionFinale = $sectionFinale; return $this; }
    public function getNiveauFinal(): ?Niveau { return $this->niveauFinal; }
    public function setNiveauFinal(?Niveau $niveauFinal): static { $this->niveauFinal = $niveauFinal; return $this; }
    public function getClasseFinale(): ?Classe { return $this->classeFinale; }
    public function setClasseFinale(?Classe $classeFinale): static { $this->classeFinale = $classeFinale; return $this; }
    public function getLangueSouhaitee(): ?string { return $this->langueSouhaitee; }
    public function setLangueSouhaitee(?string $langueSouhaitee): static { $this->langueSouhaitee = $this->nullableUpper($langueSouhaitee); return $this; }
    public function getModeSouhaite(): ?string { return $this->modeSouhaite; }
    public function setModeSouhaite(?string $modeSouhaite): static { $this->modeSouhaite = $this->nullableUpper($modeSouhaite); return $this; }
    public function getTarifPropose(): ?string { return $this->tarifPropose; }
    public function setTarifPropose(?string $tarifPropose): static { $this->tarifPropose = $tarifPropose; return $this; }
    public function getOrdre(): int { return $this->ordre; }
    public function setOrdre(int $ordre): static { $this->ordre = $ordre; return $this; }
    public function isPrincipal(): bool { return $this->principal; }
    public function setPrincipal(bool $principal): static { $this->principal = $principal; return $this; }
    public function isActif(): bool { return $this->actif; }
    public function setActif(bool $actif): static { $this->actif = $actif; return $this; }
    public function getObservation(): ?string { return $this->observation; }
    public function setObservation(?string $observation): static { $this->observation = $this->nullableTrim($observation); return $this; }
    public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; }
    public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; }

    #[ORM\PrePersist]
    public function initializeTimestamps(): void { $now = new \DateTimeImmutable(); $this->createdAt ??= $now; $this->updatedAt = $now; }
    #[ORM\PreUpdate]
    public function refreshUpdatedAt(): void { $this->updatedAt = new \DateTimeImmutable(); }
    private function nullableTrim(?string $value): ?string { $value = $value !== null ? trim($value) : null; return $value !== '' ? $value : null; }
    private function nullableUpper(?string $value): ?string { $value = $this->nullableTrim($value); return $value !== null ? mb_strtoupper($value) : null; }
}
