<?php

declare(strict_types=1);

namespace App\Entity;

use App\Enum\SharedImageStatus;
use App\Repository\SharedImageRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: SharedImageRepository::class)]
#[ORM\Index(columns: ['recipient_user_id', 'status'], name: 'idx_shared_recipient_status')]
class SharedImage
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private Image $sourceImage;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private User $recipientUser;

    #[ORM\ManyToOne]
    #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
    private User $sharedBy;

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

    #[ORM\Column(enumType: SharedImageStatus::class)]
    private SharedImageStatus $status = SharedImageStatus::Pending;

    public function __construct(Image $sourceImage, User $recipientUser, User $sharedBy)
    {
        $this->sourceImage   = $sourceImage;
        $this->recipientUser = $recipientUser;
        $this->sharedBy      = $sharedBy;
        $this->sharedAt      = new \DateTimeImmutable();
    }

    public function getId(): ?int { return $this->id; }
    public function getSourceImage(): Image { return $this->sourceImage; }
    public function getRecipientUser(): User { return $this->recipientUser; }
    public function getSharedBy(): User { return $this->sharedBy; }
    public function getSharedAt(): \DateTimeImmutable { return $this->sharedAt; }
    public function getStatus(): SharedImageStatus { return $this->status; }
    public function setStatus(SharedImageStatus $status): static { $this->status = $status; return $this; }
}
