<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SaasInvoice extends Model
{
    protected $table = 'saas_invoices';

    protected $fillable = [
        'invoice_number',
        'tenant_id',
        'subscription_id',
        'plan_id',
        'invoice_date',
        'due_date',
        'subtotal',
        'discount',
        'tax_rate',
        'tax_amount',
        'total',
        'paid_amount',
        'balance',
        'status',
        'notes',
    ];

    protected $casts = [
        'invoice_date' => 'date',
        'due_date' => 'date',
    ];

    public function tenant()
    {
        return $this->belongsTo(Tenant::class);
    }

    public function plan()
    {
        return $this->belongsTo(Plan::class);
    }

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

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