<?php

declare(strict_types=1);

namespace App\Entity;

use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
#[ORM\Table(name: 'trip')]
class Trip
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Vessel::class, inversedBy: 'trips')]
    #[ORM\JoinColumn(nullable: false)]
    private Vessel $vessel;

    #[ORM\Column(length: 255)]
    private string $pilotReference;

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

    #[ORM\ManyToOne(targetEntity: Location::class)]
    #[ORM\JoinColumn(name: 'start_location_id', nullable: false)]
    private Location $startLocation;

    #[ORM\ManyToOne(targetEntity: Location::class)]
    #[ORM\JoinColumn(name: 'end_location_id', nullable: false)]
    private Location $endLocation;

    #[ORM\Column]
    private DateTimeImmutable $startDate;

    #[ORM\Column]
    private DateTimeImmutable $endDate;

    #[ORM\Column]
    private DateTimeImmutable $createdAt;

    #[ORM\OneToMany(targetEntity: TripLocation::class, mappedBy: 'trip')]
    private Collection $tripLocations;

    #[ORM\OneToMany(targetEntity: UserTrip::class, mappedBy: 'trip')]
    private Collection $userTrips;

    public function __construct(
        Vessel $vessel,
        string $pilotageReference,
        Location $startLocation,
        Location $endLocation,
        DateTimeImmutable $startDate,
        DateTimeImmutable $endDate
    ) {
        $this->vessel = $vessel;
        $this->pilotReference = $pilotageReference;
        $this->startLocation = $startLocation;
        $this->endLocation = $endLocation;
        $this->startDate = $startDate;
        $this->endDate = $endDate;
        $this->createdAt = new DateTimeImmutable();
        $this->tripLocations = new ArrayCollection();
        $this->userTrips = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getVessel(): Vessel
    {
        return $this->vessel;
    }

    public function setVessel(Vessel $vessel): self
    {
        $this->vessel = $vessel;
        return $this;
    }

    public function getPilotReference(): string
    {
        return $this->pilotReference;
    }

    public function setPilotReference(string $pilotReference): self
    {
        $this->pilotReference = $pilotReference;
        return $this;
    }

    public function getCaptainName(): ?string
    {
        return $this->captainName;
    }

    public function setCaptainName(?string $captainName): self
    {
        $this->captainName = $captainName;
        return $this;
    }

    public function getStartLocation(): Location
    {
        return $this->startLocation;
    }

    public function setStartLocation(Location $startLocation): self
    {
        $this->startLocation = $startLocation;
        return $this;
    }

    public function getEndLocation(): Location
    {
        return $this->endLocation;
    }

    public function setEndLocation(Location $endLocation): self
    {
        $this->endLocation = $endLocation;
        return $this;
    }

    public function getStartDate(): DateTimeImmutable
    {
        return $this->startDate;
    }

    public function setStartDate(DateTimeImmutable $startDate): self
    {
        $this->startDate = $startDate;
        return $this;
    }

    public function getEndDate(): DateTimeImmutable
    {
        return $this->endDate;
    }

    public function setEndDate(DateTimeImmutable $endDate): self
    {
        $this->endDate = $endDate;
        return $this;
    }

    public function getCreatedAt(): DateTimeImmutable
    {
        return $this->createdAt;
    }

    public function getTripLocations(): Collection
    {
        return $this->tripLocations;
    }

    public function getUserTrips(): Collection
    {
        return $this->userTrips;
    }
}