<?php

namespace App\Models;

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

class Tariff extends Model
{
    use HasFactory;

    protected $table = 'tariffs';
    protected $primaryKey = 'tariff_id';

    protected $fillable = [
        'lawyer_id',
        'tier_id',
        'group_id',
        'service_code',
        'service_name',
        'service_category',
        'billing_method',
        'rate_type',
        'rate_amount',
        'currency_id',
        'billing_increment',
        'minimum_billable_mins',
        'effective_from',
        'minimum_fee',
        'maximum_fee',
        'retainer_required',
        'retainer_amount',
        'court_level',
        'complexity_level',
        'tax_inclusive',
        'vat_rate',
        'effective_to',
        'is_active',
        'deleted_at',
        'description',
        'notes',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'effective_from' => 'date',
        'effective_to' => 'date',
        'rate_amount' => 'decimal:2',
        'minimum_fee' => 'decimal:2',
        'maximum_fee' => 'decimal:2',
        'retainer_amount' => 'decimal:2',
        'vat_rate' => 'decimal:2',
        'is_active' => 'boolean',
        'deleted_at' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    public function lawyer()
    {
        return $this->belongsTo(Lawyer::class, 'lawyer_id', 'lawyer_id');
    }

    public function tier()
    {
        return $this->belongsTo(LawyerTier::class, 'tier_id', 'tier_id');
    }

    public function group()
    {
        return $this->belongsTo(LawyerGroup::class, 'group_id', 'group_id');
    }

    public function currency()
    {
        return $this->belongsTo(Currency::class, 'currency_id', 'currency_id');
    }
}
