<?php
// app/Models/Admin/AdminHotelInvoice.php

namespace App\Models\Admin;

use Illuminate\Database\Eloquent\Model;
use App\Models\Hotel;
use App\Models\User;
use App\Models\Base\TenantModel;

class AdminHotelInvoice extends TenantModel
{
    protected $table = 'admin_hotel_invoices';
    
    protected $fillable = [
        'hotel_id',
        'subscription_id',
        'invoice_number',
        'invoice_date',
        'due_date',
        'period_start',
        'period_end',
        'subtotal',
        'tax_amount',
        'discount_amount',
        'total_amount',
        'status',
        'paid_at',
        'payment_id',
        'notes',
        'pdf_path',
        'created_by'
    ];

    protected $casts = [
        'invoice_date' => 'date',
        'due_date' => 'date',
        'period_start' => 'date',
        'period_end' => 'date',
        'paid_at' => 'datetime',
        'subtotal' => 'decimal:2',
        'tax_amount' => 'decimal:2',
        'discount_amount' => 'decimal:2',
        'total_amount' => 'decimal:2'
    ];

    public function hotel()
    {
        return $this->belongsTo(Hotel::class);
    }

    public function subscription()
    {
        return $this->belongsTo(AdminHotelSubscription::class, 'subscription_id');
    }

    public function payment()
    {
        return $this->belongsTo(AdminHotelPayment::class, 'payment_id');
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function items()
    {
        return $this->hasMany(AdminHotelInvoiceItem::class, 'invoice_id');
    }
}