<?php

namespace App\Models;

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

class Invoice extends Model
{
    use HasFactory;

    protected $fillable = [
        'user_id', 'order_id', 'invoice_number', 'currency', 'subtotal', 'discount', 'tax', 'total',
        'status', 'due_date', 'price_locked_until', 'paid_at',
        'whmcs_client_id', 'whmcs_invoice_id', 'whmcs_status', 'whmcs_sync_status',
        'whmcs_sync_message', 'whmcs_synced_at', 'whmcs_payload',
    ];

    protected $casts = [
        'due_date' => 'date',
        'price_locked_until' => 'datetime',
        'paid_at' => 'datetime',
        'whmcs_synced_at' => 'datetime',
        'whmcs_payload' => 'array',
    ];

    public function items()
    {
        return $this->hasMany(InvoiceItem::class);
    }

    public function order()
    {
        return $this->belongsTo(Order::class);
    }

}
