<?php

namespace App\Models;

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

class RemotePaymentSubmission extends Model
{
    public const CHANNELS = ['mpesa', 'airtel_money', 'mixx_yas', 'bank', 'other'];
    public const STATUSES = ['pending_verification', 'approved', 'rejected'];

    protected $fillable = [
        'submission_number','loan_id','customer_id','branch_id','amount','payment_channel','transaction_reference',
        'proof_path','proof_original_name','proof_mime_type','proof_file_size','notes','status','submitted_by_type',
        'submitted_by_user_id','submitted_at','provider_code','provider_status','provider_message','verified_by','verified_at',
        'verification_notes','financial_account_id','payment_date','loan_payment_id',
    ];

    protected function casts(): array
    {
        return [
            'amount'=>'decimal:2','submitted_at'=>'datetime','verified_at'=>'datetime','payment_date'=>'datetime',
            'proof_file_size'=>'integer',
        ];
    }

    public function loan(): BelongsTo { return $this->belongsTo(Loan::class); }
    public function customer(): BelongsTo { return $this->belongsTo(Customer::class); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function submitter(): BelongsTo { return $this->belongsTo(User::class, 'submitted_by_user_id'); }
    public function verifier(): BelongsTo { return $this->belongsTo(User::class, 'verified_by'); }
    public function financialAccount(): BelongsTo { return $this->belongsTo(FinancialAccount::class); }
    public function loanPayment(): BelongsTo { return $this->belongsTo(LoanPayment::class); }
}
