<?php

namespace App\Models;

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

class CashOut extends Model
{
    use SoftDeletes;
    protected $table = 'cash_out';

    protected $fillable = [
        'client_id', 'custom_account_id', 'consignment_id', 'date', 'amount',
        'original_currency', 'original_amount', 'exchange_rate',
        'payment_method_id', 'payment_type_id', 'bank_account_id',
        'transaction_id', 'guest_bank_name', 'guest_account_no',
        'receipt_path', 'notes', 'created_by', 'updated_by',
        'vat_inclusive', 'vat_rate', 'net_amount', 'vat_amount',
        'is_hidden', 'payment_status',
        'is_transfer', 'transfer_to_bank_account_id'
    ];

    protected $casts = [
        'date' => 'date',
        'amount' => 'decimal:2',
        'original_amount' => 'decimal:2',
        'exchange_rate' => 'decimal:6',
        'vat_inclusive' => 'boolean',
        'vat_rate' => 'decimal:2',
        'net_amount' => 'decimal:2',
        'vat_amount' => 'decimal:2',
        'is_hidden' => 'boolean',
        'is_transfer' => 'boolean'
    ];

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

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

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

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

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

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

    public function transferToBankAccount(): BelongsTo
    {
        return $this->belongsTo(BankAccount::class, 'transfer_to_bank_account_id');
    }

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater(): BelongsTo
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
