<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ClientInvoiceLine extends Model
{
    protected $table = 'client_invoice_lines';

    protected $fillable = [
        'invoice_id',
        'charge_type',
        'tariff_id',
        'arrangement_id',
        'service_code',
        'service_name',
        'billing_method',
        'rate_snapshot',
        'billing_increment',
        'lawyer_id',
        'work_date_from',
        'work_date_to',
        'total_raw_minutes',
        'total_rounded_minutes',
        'quantity',
        'base_amount',
        'discount_pct',
        'discount_amount',
        'line_total',
        'description',
        'sort_order',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'work_date_from' => 'date',
        'work_date_to' => 'date',
        'rate_snapshot' => 'decimal:2',
        'quantity' => 'decimal:4',
        'base_amount' => 'decimal:2',
        'discount_pct' => 'decimal:2',
        'discount_amount' => 'decimal:2',
        'line_total' => 'decimal:2',
    ];

    public function invoice()
    {
        return $this->belongsTo(ClientInvoice::class, 'invoice_id');
    }

    public function tariff()
    {
        return $this->belongsTo(Tariff::class, 'tariff_id', 'tariff_id');
    }

    public function arrangement()
    {
        return $this->belongsTo(FeeArrangement::class, 'arrangement_id', 'arrangement_id');
    }

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