<?php

declare(strict_types=1);

namespace App\Domain\Media;

use App\Framework\Database\Attributes\Column;
use App\Framework\Database\Attributes\Entity;

#[Entity(tableName: 'image_variants')]
final readonly class ImageVariant
{
    /*#[Column(name: 'id', primary: true, autoIncrement: true)]
    public int $id;*/
    public function __construct(
        #[Column(name: 'image_id')]
        public string $imageId,
        #[Column(name: 'variant_type')]
        public string $variantType,
        // Todo: Implement Size
        #[Column(name: 'size')]
        public string $size,
        #[Column(name: 'format')]
        public string $format,
        #[Column(name: 'mime_type')]
        public string $mimeType,
        #[Column(name: 'file_size')]
        public int $fileSize,
        #[Column(name: 'width')]
        public int $width,
        #[Column(name: 'height')]
        public int $height,
        #[Column(name: 'filename')]
        public string $filename,
        #[Column(name: 'path')]
        public string $path,
        #[Column(name: 'id', primary: true, autoIncrement: true)]
        public ?int $id = null,
    ) {
    }

    public function getUrl(): string
    {
        return '/images/'. $this->filename;
    }

    public function getVariantType(): ImageVariantType
    {
        return ImageVariantType::from($this->variantType);
    }

    public function getSize(): ImageSize
    {
        return ImageSize::from($this->size);
    }

    public function getFormat(): ImageFormat
    {
        return ImageFormat::from($this->format);
    }

    public function getVariantKey(): string
    {
        return "{$this->variantType}_{$this->size}_{$this->format}";
    }
}
