<?php

namespace App\Models;

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

class MemberDue extends Model
{
    protected $fillable = [
        'user_id', 'amount', 'period', 'status', 'paid_at', 'notes', 'created_by',
    ];

    protected $casts = [
        'paid_at' => 'date',
    ];

    protected static function booted(): void
    {
        static::creating(function (MemberDue $due) {
            $due->created_by ??= auth()->id();
        });
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function creator(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
