<?php

namespace App\Models;

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

class Installment extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $fillable = [
        'account_id',
        'amount',
        'balance_before',
        'currency',
        'reference',
        'installment_at',
        'meta',
        'created_by',
        'activity_id',
    ];

    protected function casts(): array
    {
        return [
            'installment_at' => 'datetime',
            'meta' => 'array',
            'amount' => 'decimal:4',
            'balance_before' => 'decimal:4',
        ];
    }

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

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