<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class SubscriptionPayment extends Model
{
    protected $table = 'subscription_payments';

    protected $fillable = [
        'company_id',
        'employee_count',
        'amount',
        'calculated_total',
        'currency',
        'selected_addons',
        'payment_method',
        'offline_payment_mode_id',
        'status',
        'razorpay_order_id',
        'razorpay_payment_id',
        'razorpay_signature',
        'paid_at',
        'notes',
        'meta',
        'recorded_by',
    ];

    public function offlinePaymentMode(): BelongsTo
    {
        return $this->belongsTo(OfflinePaymentMode::class, 'offline_payment_mode_id');
    }

    protected $casts = [
        'amount' => 'decimal:2',
        'calculated_total' => 'decimal:2',
        'employee_count' => 'integer',
        'selected_addons' => 'array',
        'paid_at' => 'datetime',
        'meta' => 'array',
    ];

    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    public function recordedByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'recorded_by');
    }
}
