<?php

namespace App\Models\SelfPaced;

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

/**
 * CertificatePayment Model
 *
 * Records certificate fee payments (Paystack or cash).
 * One per enrollment.
 *
 * Requirements: 8.5, 8.11
 */
class CertificatePayment extends Model
{
    protected $table = 'self_paced_certificate_payments';

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

    protected $casts = [
        'amount_paid' => 'decimal:2',
        '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');
    }
}
