<?php

namespace App\Policies;

use App\Models\Shop;
use App\Models\User;

class ShopPolicy
{
    /**
     * Grant all access to super-admin.
     */
    public function before(User $user, string $ability)
    {
        if ($user->hasRole('super-admin')) {
            return true;
        }

        return null;
    }

    public function viewAny(User $user): bool
    {
        return true;
    }

    public function view(User $user, Shop $shop): bool
    {
        return $user->isShopStaff($shop);
    }

    public function create(User $user): bool
    {
        // Allow authenticated users to create shops
        return true;
    }

    public function update(User $user, Shop $shop): bool
    {
        return $user->isShopStaff($shop);
    }

    public function delete(User $user, Shop $shop): bool
    {
        return $user->isShopStaff($shop);
    }

    public function manage(User $user, Shop $shop): bool
    {
        return $this->view($user, $shop);
    }
}
