<?php

namespace Modules\MembershipApplication\Entities;

use App\Traits\HasDocuments;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Modules\Auth\Entities\User;
use Modules\MembershipApplication\Enums\ApplicationStatus;

class MembershipApplication extends Model
{
    use HasDocuments, HasUuids;

    protected $table = 'membership_applications';

    /**
     * @var list<string>
     */
    protected $fillable = [
        'application_number',
        'user_id',
        'status',
        'board_result',
        'submitted_at',
        'completed_at',
    ];

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

    protected function casts(): array
    {
        return [
            'status' => ApplicationStatus::class,
        ];
    }

    public function applicant(): HasOne
    {
        return $this->hasOne(MembershipApplicationApplicant::class);
    }

    public function heirs(): HasMany
    {
        return $this->hasMany(MembershipApplicationHeir::class);
    }

    public function references(): HasMany
    {
        return $this->hasMany(MembershipApplicationReference::class);
    }

    public function reviews(): HasMany
    {
        return $this->hasMany(MembershipApplicationReview::class);
    }

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