<?php

namespace App\Models;

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

class VideoAudioTrack extends Model
{
    protected $fillable = ['video_id', 'language', 'label', 'title', 'description', 'path', 'filename'];

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

    /** Slides explicitly owned by this track. Use Video::slidesForTrack() for fallback resolution. */
    public function slides()
    {
        return $this->hasMany(VideoSlide::class, 'audio_track_id')->orderBy('position');
    }

    public function getStreamUrlAttribute(): string
    {
        return route('videos.audio-track', ['video' => $this->video_id, 'track' => $this->id]);
    }

    /** Absolute local path to the file, regardless of NAS or local storage. */
    public function localPath(): string
    {
        return storage_path('app/' . $this->path);
    }
}
