<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;

class Album extends Model
{
    use HasFactory;

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

    public function images() : HasMany {
        return $this->hasMany(Image::class);
    }

    public function media() : Collection {
        return $this->images;
    }

    public function getThumbnailAttribute() : ?string {
        return $this->images()->where('isCover', 1)->first()?->getThumbnail();
    }
}
