<?php

namespace App\Models;

use App\Models\BaseModel;

class PaymentError extends BaseModel
{
    protected $table = 'payment_error';

    // CI: useTimestamps = false (logged_at managed manually)
    public $timestamps = false;

    protected $fillable = [
        'payment_id',
        'invoice_id',
        'parent_id',
        'wrong_paid_amount',
        'wrong_payment_method',
        'wrong_check_file',
        'error_note',
        'logged_at',
        'logged_by',
        'school_year',
        'semester',
    ];

    protected $casts = [
        'payment_id'         => 'integer',
        'invoice_id'         => 'integer',
        'parent_id'          => 'integer',
        'wrong_paid_amount'  => 'decimal:2',  // adjust precision if needed
        'logged_by'          => 'integer',
        'logged_at'          => 'datetime',
    ];

    /* Optional relationships */
    public function invoice()
    {
        return $this->belongsTo(Invoice::class, 'invoice_id');
    }

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

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