<?php

namespace Modules\MembershipApplication\Entities;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Modules\Auth\Entities\User;
use Modules\MembershipApplication\Enums\ReferenceType;

class MembershipApplicationReference extends Model
{
    use HasUuids;

    protected $table = 'membership_application_references';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'membership_application_id',
        'reference_type',
        'user_id',
        'assigned_by',
        'assigned_at',
    ];

    /**
     * @var list<string>
     */
    protected $hidden = [
    ];

    protected function casts(): array
    {
        return [
            'reference_type' => ReferenceType::class,
            'assigned_at' => 'datetime',
        ];
    }

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

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

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