<?php

namespace Modules\Auth\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class UserPolicy
{
    use HandlesAuthorization;

    public function viewAnyss(User $authUser): bool
    {
        return $authUser->can('auth.users.view');
    }

    public function view(User $authUser, User $user): bool
    {
        return $authUser->can('auth.users.view');
    }

    public function create(User $authUser): bool
    {
        return $authUser->can('auth.users.create');
    }

    public function update(User $authUser, User $user): bool
    {
        return $authUser->can('auth.users.update');
    }

    public function updateRoles(User $authUser, User $user): bool
    {
        return $authUser->can('auth.users.update-roles');
    }

    public function updateStatus(User $authUser, User $user): bool
    {
        return $authUser->id !== $user->id && $authUser->can('auth.users.status');
    }

    public function delete(User $authUser, User $user): bool
    {
        return $authUser->can('auth.users.delete');
    }

    public function profile(User $authUser, User $targetUser): bool
    {
        if ($authUser->id === $targetUser->id) {
            return true;
        }

        return $authUser->can('auth.profile.view');
    }

    public function updateProfile(User $authUser, User $targetUser): bool
    {
        if ($authUser->id === $targetUser->id) {
            return true;
        }

        return $authUser->can('auth.profile.update');
    }
}
