<?php

namespace App\Models\SelfPaced;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
 * ResitPayment Model
 *
 * Records exam re-sit fee payments (Paystack or cash).
 *
 * Requirements: 18.10, 18.13
 */
class ResitPayment extends Model
{
    protected $table = 'self_paced_resit_payments';

    protected $fillable = [
        'enrollment_id',
        'user_id',
        'course_id',
        'payment_reference',
        'payment_method',
        'amount_paid',
        'currency',
        'resit_number',
        'proof_id',
        'payment_date',
    ];

    protected $casts = [
        'amount_paid' => 'decimal:2',
        'resit_number' => 'integer',
        'payment_date' => 'datetime',
    ];

    // =====================================================================
    // Relationships
    // =====================================================================

    public function enrollment(): BelongsTo
    {
        return $this->belongsTo(Enrollment::class, 'enrollment_id');
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(related: \App\Models\User::class, 'user_id');
    }

    public function course(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id');
    }

    public function proof(): BelongsTo
    {
        return $this->belongsTo(PaymentProof::class, 'proof_id');
    }
}
