<?php

namespace App\Policies;

use App\Models\CoachRequest;
use App\Models\Payment;
use App\Models\User;

class PaymentPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->isAdmin();
    }

    public function view(User $user, Payment $payment): bool
    {
        if ($user->isAdmin()) {
            return true;
        }

        if ($user->isAthlete()) {
            return $user->id === $payment->coachRequest->athlete->user_id;
        }

        if ($user->isCoach()) {
            return $user->id === $payment->coachRequest->coach->user_id;
        }

        return false;
    }

    /**
     * تأیید/رد فقط توسط مربیِ همان درخواست یا Admin.
     */
    public function review(User $user, Payment $payment): bool
    {
        return $user->isAdmin() || ($user->isCoach() && $user->id === $payment->coachRequest->coach->user_id);
    }
}
