<?php

namespace App\Models;

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

class Paiement extends Model
{
    use HasFactory;

    protected $fillable = [
        'reference', 'payeur_type', 'payeur_id', 'type_paiement',
        'forfait_id', 'mission_id', 'montant', 'moyen_paiement',
        'numero_transaction_externe', 'statut', 'recu_par', 'notes', 'paid_at',
    ];

    protected $casts = [
        'montant' => 'decimal:2',
        'paid_at' => 'datetime',
    ];

    // Relations
    public function payeur(): \Illuminate\Database\Eloquent\Relations\MorphTo
    {
        return $this->morphTo();
    }

    public function forfait(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Forfait::class);
    }

    public function mission(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Mission::class);
    }

    public function recuPar(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'recu_par');
    }
}
