<?php

namespace App\Models;

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

class Invoice extends Model
{
    use HasFactory;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'user_id',
        'meter_reading_id',
        'pemakaian',
        'invoice_number',
        'midtrans_order_id',
        'total_amount',
        'due_date',
        'paid_at',
        'payment_method',
        'transaction_id',
        'payment_code',
        'published_at',
        'status',
        'snap_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'id' => 'integer',
        'user_id' => 'integer',
        'meter_reading_id' => 'integer',
        'due_date' => 'date',
        'paid_at' => 'datetime',
        'published_at' => 'datetime',
    ];

    /**
     * Relasi: Setiap tagihan dimiliki oleh satu User.
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * Relasi: Setiap tagihan berasal dari satu pencatatan meteran.
     */
    public function meterReading(): BelongsTo
    {
        return $this->belongsTo(MeterReading::class);
    }
}
