package fastly

import (
	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var vclAttributes = ServiceMetadata{
	ServiceTypeVCL,
}

// Ordering is important - stored is processing order
// Conditions need to be updated first, as they can be referenced by other
// configuration objects (Backends, Request Headers, etc).
var vclService = &BaseServiceDefinition{
	Type: vclAttributes.serviceType,
	Attributes: []ServiceAttributeDefinition{
		NewServiceSettings(),
		NewServiceCondition(vclAttributes),
		NewServiceDomain(vclAttributes),
		NewServiceHealthCheck(vclAttributes),
		NewServiceBackend(vclAttributes),
		NewServiceProductEnablement(vclAttributes),
		NewServiceImageOptimizerDefaultSettings(vclAttributes),
		NewServiceDirector(vclAttributes),
		NewServiceHeader(vclAttributes),
		NewServiceGzip(vclAttributes),
		NewServiceLoggingS3(vclAttributes),
		NewServiceLoggingPaperTrail(vclAttributes),
		NewServiceLoggingSumologic(vclAttributes),
		NewServiceLoggingGCS(vclAttributes),
		NewServiceLoggingBigQuery(vclAttributes),
		NewServiceLoggingSyslog(vclAttributes),
		NewServiceLoggingLogentries(vclAttributes),
		NewServiceLoggingSplunk(vclAttributes),
		NewServiceLoggingBlobStorage(vclAttributes),
		NewServiceLoggingHTTPS(vclAttributes),
		NewServiceLoggingElasticSearch(vclAttributes),
		NewServiceLoggingFTP(vclAttributes),
		NewServiceLoggingSFTP(vclAttributes),
		NewServiceLoggingDatadog(vclAttributes),
		NewServiceLoggingLoggly(vclAttributes),
		NewServiceLoggingGooglePubSub(vclAttributes),
		NewServiceLoggingGrafanaCloudLogs(vclAttributes),
		NewServiceLoggingScalyr(vclAttributes),
		NewServiceLoggingNewRelic(vclAttributes),
		NewServiceLoggingNewRelicOTLP(vclAttributes),
		NewServiceLoggingKafka(vclAttributes),
		NewServiceLoggingHeroku(vclAttributes),
		NewServiceLoggingHoneycomb(vclAttributes),
		NewServiceLoggingLogshuttle(vclAttributes),
		NewServiceLoggingOpenstack(vclAttributes),
		NewServiceLoggingDigitalOcean(vclAttributes),
		NewServiceLoggingCloudfiles(vclAttributes),
		NewServiceLoggingKinesis(vclAttributes),
		NewServiceDictionary(vclAttributes),
		NewServiceResponseObject(vclAttributes),
		NewServiceRateLimiter(vclAttributes),
		NewServiceRequestSetting(vclAttributes),
		NewServiceVCL(vclAttributes),
		NewServiceSnippet(vclAttributes),
		NewServiceDynamicSnippet(vclAttributes),
		NewServiceCacheSetting(vclAttributes),
		NewServiceACL(),
	},
}

func resourceServiceVCL() *schema.Resource {
	resource := resourceService(vclService)

	// Add schema version and state upgraders for bot_management breaking change (v9.0.0)
	resource.SchemaVersion = 1
	resource.StateUpgraders = []schema.StateUpgrader{
		{
			Version: 0,
			Type:    serviceVCLStateUpgraderV0().CoreConfigSchema().ImpliedType(),
			Upgrade: upgradeServiceVCLStateV0toV1,
		},
	}

	return resource
}
