<?php

namespace Modules\MembershipApplication\Policies;

use Illuminate\Auth\Access\HandlesAuthorization;
use Modules\MembershipApplication\Entities\MembershipApplication;

class MembershipApplicationPolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any models.
     */
    public function viewAny($user): bool
    {
        return $user->hasPermissionTo('lihat permohonan keahlian');
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('lihat permohonan keahlian');
    }

    /**
     * Management officer: approve or reject an application.
     */
    public function managementReview($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('semak permohonan keahlian pentadbiran');
    }

    /**
     * Board member: pass or fail an application.
     */
    public function boardReview($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('semak permohonan keahlian lembaga');
    }

    /**
     * General manager: send result notification and create account if passed.
     */
    public function complete($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('selesaikan permohonan keahlian');
    }

    /**
     * General manager: batch complete multiple applications.
     */
    public function completeBatch($user): bool
    {
        return $user->hasPermissionTo('selesaikan permohonan keahlian');
    }

    /**
     * Admin: assign or update proposer and supporter.
     */
    public function assignReferences($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('tetapkan pencadang penyokong');
    }

    /**
     * Admin: edit application details before completion.
     */
    public function update($user, ?MembershipApplication $membershipApplication = null): bool
    {
        return $user->hasPermissionTo('kemaskini permohonan keahlian');
    }
}
