// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

package zero_trust_test

import (
	"context"
	"errors"
	"os"
	"testing"

	"github.com/cloudflare/cloudflare-go/v6"
	"github.com/cloudflare/cloudflare-go/v6/internal/testutil"
	"github.com/cloudflare/cloudflare-go/v6/option"
	"github.com/cloudflare/cloudflare-go/v6/zero_trust"
)

func TestDeviceDeviceListWithOptionalParams(t *testing.T) {
	t.Skip("TODO: investigate prism error for invalid security scheme used")
	baseURL := "http://localhost:4010"
	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
		baseURL = envURL
	}
	if !testutil.CheckTestServer(t, baseURL) {
		return
	}
	client := cloudflare.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
		option.WithAPIEmail("user@example.com"),
	)
	_, err := client.ZeroTrust.Devices.Devices.List(context.TODO(), zero_trust.DeviceDeviceListParams{
		AccountID:           cloudflare.F("account_id"),
		ID:                  cloudflare.F([]string{"string"}),
		ActiveRegistrations: cloudflare.F(zero_trust.DeviceDeviceListParamsActiveRegistrationsInclude),
		Cursor:              cloudflare.F("cursor"),
		Include:             cloudflare.F("include"),
		LastSeenUser: cloudflare.F(zero_trust.DeviceDeviceListParamsLastSeenUser{
			Email: cloudflare.F("email"),
		}),
		PerPage:    cloudflare.F(int64(0)),
		Search:     cloudflare.F("search"),
		SeenAfter:  cloudflare.F("seen_after"),
		SeenBefore: cloudflare.F("seen_before"),
		SortBy:     cloudflare.F(zero_trust.DeviceDeviceListParamsSortByName),
		SortOrder:  cloudflare.F(zero_trust.DeviceDeviceListParamsSortOrderAsc),
	})
	if err != nil {
		var apierr *cloudflare.Error
		if errors.As(err, &apierr) {
			t.Log(string(apierr.DumpRequest(true)))
		}
		t.Fatalf("err should be nil: %s", err.Error())
	}
}

func TestDeviceDeviceDelete(t *testing.T) {
	t.Skip("TODO: investigate prism error for invalid security scheme used")
	baseURL := "http://localhost:4010"
	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
		baseURL = envURL
	}
	if !testutil.CheckTestServer(t, baseURL) {
		return
	}
	client := cloudflare.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
		option.WithAPIEmail("user@example.com"),
	)
	_, err := client.ZeroTrust.Devices.Devices.Delete(
		context.TODO(),
		"device_id",
		zero_trust.DeviceDeviceDeleteParams{
			AccountID: cloudflare.F("account_id"),
		},
	)
	if err != nil {
		var apierr *cloudflare.Error
		if errors.As(err, &apierr) {
			t.Log(string(apierr.DumpRequest(true)))
		}
		t.Fatalf("err should be nil: %s", err.Error())
	}
}

func TestDeviceDeviceGetWithOptionalParams(t *testing.T) {
	t.Skip("TODO: investigate prism error for invalid security scheme used")
	baseURL := "http://localhost:4010"
	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
		baseURL = envURL
	}
	if !testutil.CheckTestServer(t, baseURL) {
		return
	}
	client := cloudflare.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
		option.WithAPIEmail("user@example.com"),
	)
	_, err := client.ZeroTrust.Devices.Devices.Get(
		context.TODO(),
		"device_id",
		zero_trust.DeviceDeviceGetParams{
			AccountID: cloudflare.F("account_id"),
			Include:   cloudflare.F("include"),
		},
	)
	if err != nil {
		var apierr *cloudflare.Error
		if errors.As(err, &apierr) {
			t.Log(string(apierr.DumpRequest(true)))
		}
		t.Fatalf("err should be nil: %s", err.Error())
	}
}

func TestDeviceDeviceRevoke(t *testing.T) {
	t.Skip("TODO: investigate prism error for invalid security scheme used")
	baseURL := "http://localhost:4010"
	if envURL, ok := os.LookupEnv("TEST_API_BASE_URL"); ok {
		baseURL = envURL
	}
	if !testutil.CheckTestServer(t, baseURL) {
		return
	}
	client := cloudflare.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
		option.WithAPIEmail("user@example.com"),
	)
	_, err := client.ZeroTrust.Devices.Devices.Revoke(
		context.TODO(),
		"device_id",
		zero_trust.DeviceDeviceRevokeParams{
			AccountID: cloudflare.F("account_id"),
		},
	)
	if err != nil {
		var apierr *cloudflare.Error
		if errors.As(err, &apierr) {
			t.Log(string(apierr.DumpRequest(true)))
		}
		t.Fatalf("err should be nil: %s", err.Error())
	}
}
