<?php

namespace App\Models;

use App\Enums\CreditType;
use Database\Factories\CreditHistoryFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;

/**
 * Mutasi credit In/Out (RPD §12.2, BR-13).
 *
 * @property int $id
 * @property string|null $invoice
 * @property Carbon $tanggal
 * @property string|null $keterangan
 * @property int $credit
 * @property CreditType $jenis
 * @property int $user_id
 */
class CreditHistory extends Model
{
    /** @use HasFactory<CreditHistoryFactory> */
    use HasFactory;

    protected $fillable = [
        'invoice', 'tanggal', 'keterangan', 'credit', 'jenis', 'user_id',
    ];

    protected function casts(): array
    {
        return [
            'tanggal' => 'datetime',
            'credit' => 'integer',
            'jenis' => CreditType::class,
        ];
    }

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