<?php

namespace App\Models;

use App\Casts\TrimmedDecimal;
use App\Concerns\RecordsCreator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use OwenIt\Auditing\Auditable as AuditableTrait;
use OwenIt\Auditing\Contracts\Auditable;

class CurrencyExchange extends Model implements Auditable
{
    use AuditableTrait, RecordsCreator;

    /**
     * @var list<string>
     */
    protected $fillable = [
        'saraf_id',
        'exchange_date',
        'total_afn',
        'dollar_difference_price',
        'dollar_price',
        'total_dollar',
        'receive_dollar',
        'remain_dollar_on_saraf',
    ];

    /**
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'saraf_id' => 'integer',
            'exchange_date' => 'date',
            'total_afn' => TrimmedDecimal::class.':2',
            'dollar_difference_price' => TrimmedDecimal::class.':4',
            'dollar_price' => TrimmedDecimal::class.':4',
            'total_dollar' => TrimmedDecimal::class.':2',
            'receive_dollar' => TrimmedDecimal::class.':2',
            'remain_dollar_on_saraf' => TrimmedDecimal::class.':2',
        ];
    }

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

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