<?php

namespace App\Domains\Attachable\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

#[Fillable([
    'attachment_id',
    'variant',
    'crop_horizontal',
    'crop_vertical',
    'cropped_attachment_id',
])]
class AttachmentCrop extends Model
{
    public const DESKTOP = 'desktop';

    public const MOBILE = 'mobile';

    public const VARIANTS = [self::DESKTOP, self::MOBILE];

    protected function casts(): array
    {
        return [
            'attachment_id' => 'integer',
            'crop_horizontal' => 'array',
            'crop_vertical' => 'array',
            'cropped_attachment_id' => 'integer',
        ];
    }

    public function attachment(): BelongsTo
    {
        return $this->belongsTo(Attachment::class);
    }

    public function croppedAttachment(): BelongsTo
    {
        return $this->belongsTo(Attachment::class, 'cropped_attachment_id');
    }
}
