<?php

namespace App\Models;

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

class PassengerExtraService extends Model
{
    protected $fillable = [
        'title',
        'subtitle',
        'description',
        'image_path',
        'price_estimate',
        'sort_order',
        'is_active',
    ];

    protected $casts = [
        'price_estimate' => 'decimal:2',
        'sort_order' => 'integer',
        'is_active' => 'boolean',
    ];

    public function requests(): HasMany
    {
        return $this->hasMany(PassengerExtraServiceRequest::class, 'passenger_extra_service_id');
    }

    public function items(): HasMany
    {
        return $this->hasMany(PassengerExtraServiceItem::class, 'passenger_extra_service_id');
    }

    public function imagePublicUrl(): ?string
    {
        if (empty($this->image_path)) {
            return null;
        }

        // عبر مسار API يتجنب أعطال symlink أو إعداد Apache لـ /storage/ (أحياناً 500 للصور).
        return url('/api/passenger-extra-service-media?path='.rawurlencode($this->image_path));
    }
}
