<?php

namespace App\Policies;

use App\Models\User\User;

class UserPolicy {
    public function view(User $actor): bool {
        return $actor->can('users.view');
    }

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

    public function edit(User $actor, User $target): bool {
        return $actor->can('users.update');
    }

    public function delete(User $actor, User $target): bool {
        return $actor->can('users.delete') && $actor->id !== $target->id;
    }

    public function manageRoles(User $actor, User $target): bool {
        return $actor->can('users.roles.manage');
    }

    public function impersonate(User $actor, User $target): bool {
        return $actor->can('users.impersonate') && $actor->id !== $target->id;
    }

    public function viewApiKeys(User $actor, User $target) {
        return $actor->can('users.api-keys.manage');
    }

    public function manageApiKeys(User $actor, User $target) {
        return $actor->can('users.api-keys.manage');
    }

    public function manageSessions(User $actor, User $target) {
        return $actor->can('users.sessions.manage');
    }

    public function toggleStatus(User $actor, User $target): bool {
        return $actor->can('users.status.toggle') && $actor->id !== $target->id;
    }

    public function viewHistory(User $actor, User $target): bool {
        return $actor->can('users.history.view');
    }
}
