<?php

namespace App\Models;

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

class Invoice extends Model
{
    protected $fillable = ['invoice_number', 'customer_id', 'walk_in_name', 'walk_in_phone', 'user_id', 'sale_type', 'currency_code', 'exchange_rate', 'subtotal', 'discount', 'total', 'paid_amount', 'due_amount', 'status', 'invoice_date', 'notes'];
    protected function casts(): array { return ['invoice_date' => 'date', 'subtotal' => 'decimal:2', 'discount' => 'decimal:2', 'total' => 'decimal:2', 'paid_amount' => 'decimal:2', 'due_amount' => 'decimal:2']; }
    public function customer(): BelongsTo { return $this->belongsTo(Customer::class); }
    public function user(): BelongsTo { return $this->belongsTo(User::class); }
    public function items(): HasMany { return $this->hasMany(InvoiceItem::class); }
    public function payments(): HasMany { return $this->hasMany(Payment::class); }
}
