<?php

namespace App\Models;

use App\Support\MediaUrl;
use Illuminate\Database\Eloquent\Model;

class Season extends Model
{
    protected $fillable = [
        'anime_id', 'season_number', 'mal_id', 'title', 'description',
        'cover_image', 'release_year', 'is_published',
    ];

    protected $casts = ['is_published' => 'boolean'];

    public function anime()
    {
        return $this->belongsTo(Anime::class);
    }

    public function episodes()
    {
        return $this->hasMany(Episode::class)->orderBy('episode_number');
    }

    public function getCoverUrlAttribute(): ?string
    {
        return MediaUrl::fromStoragePath($this->cover_image);
    }
}
