<?php

namespace App\Models;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;

class Service extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id',
        'category_id',
        'authority_id',
        'service_code',
        'name_en',
        'name_ar',
        'description',
        'estimated_processing_days',
        'gov_fee',
        'typing_fee',
        'service_charge',
        'vat_applicable',
        'vat_amount',
        'total_price',
        'is_available_all_branches',
        'status',
    ];

    protected $casts = [
        'vat_applicable' => 'boolean',
        'is_available_all_branches' => 'boolean',
    ];

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

    public function authority()
    {
        return $this->belongsTo(ServiceAuthority::class, 'authority_id');
    }

    public function versions()
    {
        return $this->hasMany(ServiceVersion::class);
    }

    public function forms()
    {
        return $this->hasMany(ServiceForm::class);
    }

    public function documentRules()
    {
        return $this->hasMany(ServiceDocumentRule::class);
    }

    public function feeComponents()
    {
        return $this->hasMany(ServiceFeeComponent::class);
    }

    public function workflowStages()
    {
        return $this->hasMany(WorkflowStage::class)->orderBy('display_order');
    }

    public function workflowTransitions()
    {
        return $this->hasMany(WorkflowTransition::class);
    }

    public function renewalRule()
    {
        return $this->hasOne(ServiceRenewalRule::class);
    }
}
