<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Transaction extends Model
{
    protected $table = 'transactions';

    protected $fillable = [
        'invoice_number',
        'transaction_date',
        'customer_name',
        'payment_status',
        'total',
        'paid_amount',
        'change_amount',
    ];

    protected $casts = [
        'transaction_date' => 'datetime',
        'total' => 'integer',
        'paid_amount' => 'integer',
        'change_amount' => 'integer',
    ];

    public function details()
    {
        return $this->hasMany(
            TransactionDetail::class,
            'transaction_id'
        );
    }

    public function debtPayments()
    {
        return $this->hasMany(
            DebtPayment::class,
            'transaction_id'
        );
    }
}