<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class NewspaperPage extends Model
{
    use HasFactory;

    protected $fillable = [
        'newspaper_id',
        'page_number',
        'title',
        'image_path',
        'thumbnail_path',
        'sort_order',
    ];

    public function newspaper()
    {
        return $this->belongsTo(Newspaper::class);
    }

    public function hotspots()
    {
        return $this->hasMany(Hotspot::class)->where('is_active', true);
    }

    public function getImageUrlAttribute()
    {
        return asset('storage/' . $this->image_path);
    }

    public function getThumbnailUrlAttribute()
    {
        if ($this->thumbnail_path) {
            return asset('storage/' . $this->thumbnail_path);
        }
        return asset('storage/' . $this->image_path);
    }
}
