<?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\Relations\HasMany;

class Transaksi extends Model
{
    use HasFactory;

    // Nama tabel, jika tidak sesuai dengan nama default
    protected $table = 'transaksi';

    // Kolom yang dapat diisi
    protected $fillable = [
        'transaction_code',
        'user_id',
        'reservasi_id',
        'total_amount',
        'final_amount',
        'status',
        'payment_method',
        'payment_proof',
        'paid_at',
        'notes'
    ];

    protected $casts = [
        'paid_at' => 'datetime'
    ];

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

    // Relasi dengan model Reservasi
    public function reservasi(): BelongsTo
    {
        return $this->belongsTo(Reservasi::class);
    }

    // Relasi dengan model TransaksiItem
    public function items(): HasMany
    {
        return $this->hasMany(TransaksiItem::class);
    }
}
