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

package magic_transit_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/magic_transit"
	"github.com/cloudflare/cloudflare-go/v6/option"
)

func TestGRETunnelNewWithOptionalParams(t *testing.T) {
	t.Skip("TODO: investigate broken test")
	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.MagicTransit.GRETunnels.New(context.TODO(), magic_transit.GRETunnelNewParams{
		AccountID:              cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
		CloudflareGREEndpoint:  cloudflare.F("203.0.113.1"),
		CustomerGREEndpoint:    cloudflare.F("203.0.113.1"),
		InterfaceAddress:       cloudflare.F("192.0.2.0/31"),
		Name:                   cloudflare.F("GRE_1"),
		AutomaticReturnRouting: cloudflare.F(true),
		BGP: cloudflare.F(magic_transit.GRETunnelNewParamsBGP{
			CustomerASN:   cloudflare.F(int64(0)),
			ExtraPrefixes: cloudflare.F([]string{"string"}),
			Md5Key:        cloudflare.F("md5_key"),
		}),
		Description: cloudflare.F("Tunnel for ISP X"),
		HealthCheck: cloudflare.F(magic_transit.GRETunnelNewParamsHealthCheck{
			Direction: cloudflare.F(magic_transit.GRETunnelNewParamsHealthCheckDirectionBidirectional),
			Enabled:   cloudflare.F(true),
			Rate:      cloudflare.F(magic_transit.HealthCheckRateLow),
			Target: cloudflare.F[magic_transit.GRETunnelNewParamsHealthCheckTargetUnion](magic_transit.GRETunnelNewParamsHealthCheckTargetMagicHealthCheckTarget{
				Saved: cloudflare.F("203.0.113.1"),
			}),
			Type: cloudflare.F(magic_transit.HealthCheckTypeRequest),
		}),
		InterfaceAddress6: cloudflare.F("2606:54c1:7:0:a9fe:12d2:1:200/127"),
		Mtu:               cloudflare.F(int64(0)),
		TTL:               cloudflare.F(int64(0)),
		XMagicNewHcTarget: cloudflare.F(true),
	})
	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 TestGRETunnelUpdateWithOptionalParams(t *testing.T) {
	t.Skip("TODO: investigate broken test")
	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.MagicTransit.GRETunnels.Update(
		context.TODO(),
		"023e105f4ecef8ad9ca31a8372d0c353",
		magic_transit.GRETunnelUpdateParams{
			AccountID:              cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
			CloudflareGREEndpoint:  cloudflare.F("203.0.113.1"),
			CustomerGREEndpoint:    cloudflare.F("203.0.113.1"),
			InterfaceAddress:       cloudflare.F("192.0.2.0/31"),
			Name:                   cloudflare.F("GRE_1"),
			AutomaticReturnRouting: cloudflare.F(true),
			Description:            cloudflare.F("Tunnel for ISP X"),
			HealthCheck: cloudflare.F(magic_transit.GRETunnelUpdateParamsHealthCheck{
				Direction: cloudflare.F(magic_transit.GRETunnelUpdateParamsHealthCheckDirectionBidirectional),
				Enabled:   cloudflare.F(true),
				Rate:      cloudflare.F(magic_transit.HealthCheckRateLow),
				Target: cloudflare.F[magic_transit.GRETunnelUpdateParamsHealthCheckTargetUnion](magic_transit.GRETunnelUpdateParamsHealthCheckTargetMagicHealthCheckTarget{
					Saved: cloudflare.F("203.0.113.1"),
				}),
				Type: cloudflare.F(magic_transit.HealthCheckTypeRequest),
			}),
			InterfaceAddress6: cloudflare.F("2606:54c1:7:0:a9fe:12d2:1:200/127"),
			Mtu:               cloudflare.F(int64(0)),
			TTL:               cloudflare.F(int64(0)),
			XMagicNewHcTarget: cloudflare.F(true),
		},
	)
	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 TestGRETunnelListWithOptionalParams(t *testing.T) {
	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.MagicTransit.GRETunnels.List(context.TODO(), magic_transit.GRETunnelListParams{
		AccountID:         cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
		XMagicNewHcTarget: cloudflare.F(true),
	})
	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 TestGRETunnelDeleteWithOptionalParams(t *testing.T) {
	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.MagicTransit.GRETunnels.Delete(
		context.TODO(),
		"023e105f4ecef8ad9ca31a8372d0c353",
		magic_transit.GRETunnelDeleteParams{
			AccountID:         cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
			XMagicNewHcTarget: cloudflare.F(true),
		},
	)
	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 TestGRETunnelBulkUpdateWithOptionalParams(t *testing.T) {
	t.Skip("TODO: investigate broken test")
	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.MagicTransit.GRETunnels.BulkUpdate(context.TODO(), magic_transit.GRETunnelBulkUpdateParams{
		AccountID:         cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
		Body:              map[string]interface{}{},
		XMagicNewHcTarget: cloudflare.F(true),
	})
	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 TestGRETunnelGetWithOptionalParams(t *testing.T) {
	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.MagicTransit.GRETunnels.Get(
		context.TODO(),
		"023e105f4ecef8ad9ca31a8372d0c353",
		magic_transit.GRETunnelGetParams{
			AccountID:         cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
			XMagicNewHcTarget: cloudflare.F(true),
		},
	)
	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())
	}
}
