<?php

namespace App\Models;

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

class ClientQuotation extends Model
{
    use HasFactory;

    protected $table = 'client_quotations';

    protected $fillable = [
        'client_id',
        'client_name',
        'quotation_number',
        'quotation_date',
        'matter_id',
        'case_id',
        'responsible_lawyer',
        'terms',
        'validity_days',
        'scope_of_work',
        'notes',
        'currency_id',
        'subtotal',
        'tax_total',
        'discount_total',
        'status',
        'total_amount',
        'sent_at',
        'responded_at',
        'converted_invoice_id',
        'created_by',
        'updated_by',
    ];

    protected $casts = [
        'quotation_date' => 'date',
        'subtotal' => 'decimal:2',
        'tax_total' => 'decimal:2',
        'discount_total' => 'decimal:2',
        'total_amount' => 'decimal:2',
        'sent_at' => 'datetime',
        'responded_at' => 'datetime',
    ];

    public function client()
    {
        return $this->belongsTo(Client::class, 'client_id');
    }

    public function lines()
    {
        return $this->hasMany(ClientQuotationLine::class, 'quotation_id');
    }
}
