<?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 mutations() : HasMany {
        return $this->hasMany(BatchMutation::class);
    }

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

    public function getHasCoverAttribute() : bool {
        return $this->images()->where('isCover', 1)->count() > 0;
    }

    public function getHasProcessingMediaAttribute() : bool  {
        return $this->images()->where('isProcessing', 1)->count() > 0;
    }

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