<?php

namespace App\Models;

use App\Models\Disk\DiskItem;
use Illuminate\Database\Eloquent\Model;

class ResourceImage extends Model
{
    protected $fillable = [
        'resource_id',
        'disk_item_id',
        'sort_order',
        'is_cover',
    ];

    protected function casts(): array
    {
        return [
            'is_cover' => 'boolean',
            'sort_order' => 'integer',
        ];
    }

    public function resource()
    {
        return $this->belongsTo(Resource::class);
    }

    public function diskItem()
    {
        return $this->belongsTo(DiskItem::class);
    }

    public function getImageUrlAttribute(): ?string
    {
        return $this->diskItem?->full_url;
    }
}
