<?php

namespace App\Policies;

use App\Models\Coach;
use App\Models\User;

/**
 * نسخه به‌روزشده‌ی Phase 3 — نسخه Phase 2 را جایگزین کنید.
 * تغییر نسبت به Phase 2: افزوده شدن reject/disable/enable (approve از قبل بود).
 */
class CoachPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->isAdmin();
    }

    public function view(?User $user, Coach $coach): bool
    {
        if ($coach->isApproved()) {
            return true;
        }

        if (! $user) {
            return false;
        }

        return $user->isAdmin() || $user->id === $coach->user_id;
    }

    public function update(User $user, Coach $coach): bool
    {
        return $user->isAdmin() || $user->id === $coach->user_id;
    }

    public function approve(User $user, Coach $coach): bool
    {
        return $user->isAdmin();
    }

    public function reject(User $user, Coach $coach): bool
    {
        return $user->isAdmin();
    }

    public function disable(User $user, Coach $coach): bool
    {
        return $user->isAdmin();
    }

    public function enable(User $user, Coach $coach): bool
    {
        return $user->isAdmin();
    }
}
