<?php

namespace App\Models;

use App\Casts\TrimmedDecimal;
use App\Concerns\RecordsCreator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SalePayment extends Model
{
    use RecordsCreator;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'sale_id',
        'payment_type',
        'currency',
        'amount',
        'bill_amount',
        'exchange_rate',
        'paid_at',
        'payment_method',
        'reference',
        'notes',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'sale_id' => 'integer',
            'amount' => TrimmedDecimal::class.':2',
            'bill_amount' => TrimmedDecimal::class.':2',
            'exchange_rate' => TrimmedDecimal::class.':4',
            'paid_at' => 'date',
        ];
    }

    /**
     * @return BelongsTo<Sale, $this>
     */
    public function sale(): BelongsTo
    {
        return $this->belongsTo(Sale::class);
    }
}
