<?php

namespace App\Models;

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

class Service extends Model
{
    protected $fillable = [
        'service_category_id', 'name', 'slug', 'icon', 'badge',
        'short_description', 'description', 'what_you_get',
        'process_timeline', 'important_note',
        'sort_order', 'is_active', 'is_featured',
        'pricing_type', 'allow_online_payment', 'allow_manual_payment',
        'allow_partial_payment', 'allow_consultation', 'partial_payment_percentage'
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'is_featured' => 'boolean',
        'what_you_get' => 'array',
        'process_timeline' => 'array',
        'allow_online_payment' => 'boolean',
        'allow_manual_payment' => 'boolean',
        'allow_partial_payment' => 'boolean',
        'allow_consultation' => 'boolean',
        'partial_payment_percentage' => 'integer',
    ];

    public function category(): BelongsTo
    {
        return $this->belongsTo(ServiceCategory::class, 'service_category_id');
    }

    public function packages(): HasMany
    {
        return $this->hasMany(ServicePackage::class)->orderBy('sort_order');
    }

    public function requirements(): HasMany
    {
        return $this->hasMany(ServiceRequirement::class)->orderBy('sort_order');
    }

    public function faqs(): HasMany
    {
        return $this->hasMany(Faq::class)->orderBy('sort_order');
    }

    public function orders(): HasMany
    {
        return $this->hasMany(Order::class);
    }

    public function getRouteKeyName(): string
    {
        return 'slug';
    }
}
