<?php

namespace App\Models;

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

class Transaction extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'deskripsi',
        'jumlah',
        'tipe',
        'tanggal',
        'user_id',
        'mata_uang' // Tambahkan ini agar bisa diisi (mass assignment)
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'tanggal' => 'date',
        'jumlah'  => 'decimal:2',
    ];

    /**
     * Relasi ke model User
     * Memungkinkan Anda memanggil $transaction->user
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}