<?php

namespace App\Models;

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

class ExpenseItem extends Model
{
    protected $fillable = [
        'expense_id', 'expense_category_id', 'item_name', 'description', 'hsn_sac', 'unit',
        'quantity', 'rate', 'discount_percent', 'discount', 'tax_rate',
        'cgst_rate', 'sgst_rate', 'igst_rate',
        'tax_amount', 'cgst_amount', 'sgst_amount', 'igst_amount', 'amount',
    ];

    protected $casts = [
        'quantity' => 'decimal:3',
        'rate' => 'decimal:2',
        'discount_percent' => 'decimal:2',
        'discount' => 'decimal:2',
    ];

    public function expense(): BelongsTo
    {
        return $this->belongsTo(Expense::class);
    }

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