<?php

namespace App\Policies;

use App\Models\CloudflareCredential;
use App\Models\User;

class CloudflareCredentialPolicy
{
    /**
     * Determine whether the user can view any credentials.
     */
    public function viewAny(User $user): bool
    {
        return true;
    }

    /**
     * Determine whether the user can view the credential.
     */
    public function view(User $user, CloudflareCredential $credential): bool
    {
        // User poate vedea propriile credentiale sau cele default
        return $credential->user_id === $user->id
            || $credential->is_default
            || $user->isAdmin();
    }

    /**
     * Determine whether the user can create credentials.
     */
    public function create(User $user): bool
    {
        return true;
    }

    /**
     * Determine whether the user can update the credential.
     */
    public function update(User $user, CloudflareCredential $credential): bool
    {
        return $credential->user_id === $user->id || $user->isAdmin();
    }

    /**
     * Determine whether the user can delete the credential.
     */
    public function delete(User $user, CloudflareCredential $credential): bool
    {
        return $credential->user_id === $user->id || $user->isAdmin();
    }
}
