<?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: 'user_trip')]
#[ORM\UniqueConstraint(name: "unique_user_trip", columns: ["trip_id", "user_id"])]
class UserTrip
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne(targetEntity: Trip::class, inversedBy: 'userTrips')]
    #[ORM\JoinColumn(nullable: false)]
    private Trip $trip;

    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'userTrips')]
    #[ORM\JoinColumn(nullable: false)]
    private User $user;

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

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: true, onDelete: "SET NULL")]
    private ?MediaObject $signature = null;

    #[ORM\Column(nullable: false)]
    private bool $completed = false;

    #[ORM\Column(nullable: false)]
    private bool $approved = false;

    #[ORM\Column(nullable: true)]
    private ?DateTimeImmutable $completedDate;

    #[ORM\Column]
    private DateTimeImmutable $createdAt;

    #[ORM\OneToMany(targetEntity: UserTripEvent::class, mappedBy: 'userTrip')]
    private Collection $userTripEvents;

    public function __construct(
        Trip $trip,
        User $user,
    ) {
        $this->trip = $trip;
        $this->user = $user;
        $this->completed = false;
        $this->createdAt = new DateTimeImmutable();
        $this->userTripEvents = new ArrayCollection();
    }

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

    public function getTrip(): Trip
    {
        return $this->trip;
    }

    public function setTrip(Trip $trip): self
    {
        $this->trip = $trip;
        return $this;
    }

    public function getUser(): User
    {
        return $this->user;
    }

    public function setUser(User $user): self
    {
        $this->user = $user;
        return $this;
    }

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

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

    public function getSignature(): ?MediaObject
    {
        return $this->signature;
    }

    public function setSignature(?MediaObject $signature): void
    {
        $this->signature = $signature;
    }

    public function getCompletedDate(): ?DateTimeImmutable
    {
        return $this->completedDate;
    }

    public function setCompletedDate(?DateTimeImmutable $completedDate): void
    {
        $this->completedDate = $completedDate;
    }

    public function isCompleted(): bool
    {
        return $this->completed;
    }

    public function setCompleted(bool $completed): void
    {
        $this->completed = $completed;
    }

    public function isApproved(): bool
    {
        return $this->approved;
    }

    public function setApproved(bool $approved): void
    {
        $this->approved = $approved;
    }

    public function getUserTripEvents(): Collection
    {
        return $this->userTripEvents;
    }

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