<?php

declare(strict_types=1);

namespace Modules\{{ Module }}\Policies;

use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Modules\{{ Module }}\Models\{{ Entity }};

/**
 * Permissions are granular strings owned by this module and seeded on install.
 * Roles are collections of permissions edited by the Super Admin, which is why
 * "add a new role" is a data change and not a code change.
 */
final class {{ Entity }}Policy
{
    use HandlesAuthorization;

    public function viewAny(User $user): bool
    {
        return $user->can('{{ key }}.view');
    }

    public function view(User $user, {{ Entity }} ${{ entity }}): bool
    {
        return $user->can('{{ key }}.view');
    }

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

    public function update(User $user, {{ Entity }} ${{ entity }}): bool
    {
        return $user->can('{{ key }}.update');
    }

    public function delete(User $user, {{ Entity }} ${{ entity }}): bool
    {
        return $user->can('{{ key }}.delete');
    }

    public function restore(User $user, {{ Entity }} ${{ entity }}): bool
    {
        return $user->can('{{ key }}.delete');
    }
}
