<?php

namespace App\Models\Rental;

use App\Models\Customer;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Receipt extends Model
{
    protected $fillable = [
        'receipt_number',
        'rental_id',
        'customer_id',
        'invoice_id',
        'amount',
        'payment_method',
        'payment_type',
        'reference_number',
        'notes',
        'received_by',
        'status',
        'receipt_date',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'receipt_date' => 'datetime',
    ];

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

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

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

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

    public function getPaymentMethodLabelAttribute()
    {
        return [
            'cash' => 'نقدي',
            'card' => 'بطاقة',
            'transfer' => 'تحويل',
            'mada' => 'مدى',
            'visa' => 'فيزا',
            'stcpay' => 'STC Pay',
        ][$this->payment_method] ?? $this->payment_method;
    }
}
