<?php

namespace App\Models;

use App\Enums\ChargeStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class LineBillingCharge extends Model
{
    use HasFactory;

    protected $fillable = [
        'line_id', 'billing_period_id', 'invoice_id', 'plan_id', 'amount', 'status',
    ];

    protected $casts = [
        'amount' => 'decimal:2',
        'status' => ChargeStatus::class,
    ];

    public function line(): BelongsTo
    {
        return $this->belongsTo(Line::class);
    }

    public function billingPeriod(): BelongsTo
    {
        return $this->belongsTo(BillingPeriod::class);
    }

    public function invoice(): BelongsTo
    {
        return $this->belongsTo(Invoice::class);
    }

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

    public function allocations(): HasMany
    {
        return $this->hasMany(PaymentAllocation::class);
    }
}
