<?php

/*
 * This file is part of the Serenity package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Serenity\MediaBundle\Entity;

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Serenity\CoreBundle\Shared\Common\AutoIdentifierInterface;
use Serenity\CoreBundle\Shared\Common\AutoIdentifierTrait;
use Serenity\CoreBundle\Shared\Common\TimestampTrait;
use Serenity\CoreBundle\Shared\Feature\OwnerInterface;
use Serenity\CoreBundle\Shared\Feature\OwnerTrait;
use Serenity\CoreBundle\Shared\Feature\SerenitySaasInterface;
use Serenity\CoreBundle\Shared\Feature\SerenitySaasTrait;
use Serenity\CoreBundle\Shared\Feature\SortableInterface;
use Serenity\CoreBundle\Shared\Feature\SortableTrait;
use Serenity\MediaBundle\Doctrine\Repository\AttachmentRepository;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Serializer\Attribute\Ignore;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Entity\File as EmbeddedFile;
use Vich\UploaderBundle\Mapping\Attribute as Vich;

#[ORM\Entity(repositoryClass: AttachmentRepository::class)]
#[ORM\Table(name: 'serenity_media_attachment')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap(['Image' => Image::class, 'File' => File::class, 'Video' => Video::class, 'Media' => Media::class])]
#[ORM\HasLifecycleCallbacks]
#[Vich\Uploadable]
abstract class Attachment implements AutoIdentifierInterface, SerenitySaasInterface, OwnerInterface, SortableInterface
{
    use AutoIdentifierTrait;
    use OwnerTrait;
    use SerenitySaasTrait;
    use SortableTrait;
    use TimestampTrait;

    #[Assert\Length(max: 255)]
    #[ORM\Column(type: Types::STRING, nullable: true)]
    private ?string $style = null;

    #[Assert\Length(max: 255)]
    #[ORM\Column(type: Types::STRING, nullable: true)]
    private ?string $alt = null;

    #[Assert\Length(max: 255)]
    #[ORM\Column(type: Types::STRING, nullable: true)]
    private ?string $credit = null;

    #[Gedmo\SortableGroup]
    #[ORM\Column(type: UuidType::NAME, nullable: true)]
    private ?Uuid $parentId = null;

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

    #[ORM\Embedded(class: 'Vich\UploaderBundle\Entity\File')]
    #[Ignore]
    protected ?EmbeddedFile $file = null;

    public function __construct()
    {
        $this->file = new EmbeddedFile();
    }

    public function setId(Uuid $id): void
    {
        $this->id = $id;
    }

    public function getFile(): ?EmbeddedFile
    {
        return $this->file;
    }

    public function setFile(?EmbeddedFile $file = null): void
    {
        $this->file = $file;
    }

    public function getStyle(): ?string
    {
        return $this->style;
    }

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

    public function getAlt(): ?string
    {
        return $this->alt;
    }

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

    public function getCredit(): ?string
    {
        return $this->credit;
    }

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

    public function getParentId(): ?Uuid
    {
        return $this->parentId;
    }

    public function setParentId(?Uuid $parentId): void
    {
        $this->parentId = $parentId;
    }

    public function getParentClass(): ?string
    {
        return $this->parentClass;
    }

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