<?php

namespace App\Models;

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

class Premium_payment extends Model
{
    use HasFactory, SoftDeletes;

    /**
     * The attributes that are mass assignable.
     */
    protected $fillable = [
        'cover_id',
        'member_id',
        'payment_method',
        'cash_tendered',
        'amount_paid',
        'payment_change',
        'payment_date',
        'months',
        'user_id',
        'cash',
        'cash_date',
        'status',
    ];

    /**
     * Relationships
     */
    public function member()
    {
        return $this->belongsTo(Member::class, 'member_id');
    }

    public function mode()
    {
        return $this->belongsTo(Payment_mode::class, 'payment_method');
    }

    public function cover()
    {
        return $this->belongsTo(Cover::class, 'cover_id');
    }

    public function agent()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    /**
     * ✅ Fix: Define the monthsCovered() Relationship
     * A premium payment can have multiple months covered.
     */
    public function monthsCovered()
    {
        return $this->hasMany(Months_covered::class, 'payment_id');
    }
}
