<?php

namespace App\Policies;

use App\Models\AuthorisedPartner;
use App\Models\User;

class AuthorisedPartnerPolicy
{
    public function viewAny(User $user): bool
    {
        return $user->isSuperAdmin() || $user->isPromoter();
    }

    public function view(User $user, AuthorisedPartner $authorisedPartner): bool
    {
        if ($user->isSuperAdmin()) {
            return true;
        }

        return $user->isPromoter()
            && $user->promoter
            && $authorisedPartner->promoter_id === $user->promoter->id;
    }

    public function create(User $user): bool
    {
        return $user->isSuperAdmin() || $user->isPromoter();
    }

    public function update(User $user, AuthorisedPartner $authorisedPartner): bool
    {
        return $this->view($user, $authorisedPartner);
    }

    public function delete(User $user, AuthorisedPartner $authorisedPartner): bool
    {
        return $this->view($user, $authorisedPartner);
    }

    public function approve(User $user, AuthorisedPartner $authorisedPartner): bool
    {
        return $this->view($user, $authorisedPartner);
    }
}
