<?php

namespace Modules\WebPilotAI\Policies; // Adjust if needed

use App\Models\User;
use Illuminate\Support\Facades\Log; // Add this line
use Modules\WebPilotAI\Models\Website;
use Illuminate\Auth\Access\HandlesAuthorization;

class WebsitePolicy
{
    use HandlesAuthorization;

    /**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return true; // Or based on permissions
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, Website $website): bool
    {
        return $user->id === $website->user_id;
    }

    /**
     * Determine whether the user can create models.
     */
    public function create(User $user): bool
    {
        return true; // Or based on subscription/permissions
    }

    /**
     * Determine whether the user can update the model.
     */
    public function update(User $user, Website $website): bool
    {
        $isOwner = $user->id === $website->user_id;
        Log::debug("[WebsitePolicy@update] Checking update permission for website ID: {$website->id}. Website User ID: {$website->user_id}. Authenticated User ID: {$user->id}. Is Owner: " . ($isOwner ? 'Yes' : 'No'));
        return $isOwner;
    }

    /**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, Website $website): bool
    {
        return $user->id === $website->user_id;
    }

    /**
     * Determine whether the user can deploy the model.
     */
    public function deploy(User $user, Website $website): bool
    {
        return $user->id === $website->user_id;
    }

    // Add other policy methods as needed (restore, forceDelete)
}
