package awscloudfront

import (
	_init_ "github.com/aws/aws-cdk-go/awscdk/v2/jsii"
	_jsii_ "github.com/aws/jsii-runtime-go/runtime"

	"github.com/aws/aws-cdk-go/awscdk/v2"
	"github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront/internal"
	"github.com/aws/aws-cdk-go/awscdk/v2/awscloudwatch"
	"github.com/aws/aws-cdk-go/awscdk/v2/awsiam"
	"github.com/aws/constructs-go/constructs/v10"
)

// A CloudFront distribution with associated origin(s) and caching behavior(s).
//
// Example:
//   var s3Bucket bucket
//   // Add a cloudfront Function to a Distribution
//   cfFunction := cloudfront.NewFunction(this, jsii.String("Function"), &FunctionProps{
//   	Code: cloudfront.FunctionCode_FromInline(jsii.String("function handler(event) { return event.request }")),
//   	Runtime: cloudfront.FunctionRuntime_JS_2_0(),
//   })
//   cloudfront.NewDistribution(this, jsii.String("distro"), &DistributionProps{
//   	DefaultBehavior: &BehaviorOptions{
//   		Origin: origins.NewS3Origin(s3Bucket),
//   		FunctionAssociations: []functionAssociation{
//   			&functionAssociation{
//   				Function: cfFunction,
//   				EventType: cloudfront.FunctionEventType_VIEWER_REQUEST,
//   			},
//   		},
//   	},
//   })
//
type Distribution interface {
	awscdk.Resource
	IDistribution
	// The distribution ARN for this distribution.
	DistributionArn() *string
	// The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
	DistributionDomainName() *string
	// The distribution ID for this distribution.
	DistributionId() *string
	DistributionRef() *DistributionReference
	// The domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
	DomainName() *string
	// The environment this resource belongs to.
	//
	// For resources that are created and managed by the CDK
	// (generally, those created by creating new class instances like Role, Bucket, etc.),
	// this is always the same as the environment of the stack they belong to;
	// however, for imported resources
	// (those obtained from static methods like fromRoleArn, fromBucketName, etc.),
	// that might be different than the stack they were imported into.
	Env() *awscdk.ResourceEnvironment
	// The tree node.
	Node() constructs.Node
	// Returns a string-encoded token that resolves to the physical name that should be passed to the CloudFormation resource.
	//
	// This value will resolve to one of the following:
	// - a concrete value (e.g. `"my-awesome-bucket"`)
	// - `undefined`, when a name should be generated by CloudFormation
	// - a concrete name generated automatically during synthesis, in
	//   cross-environment scenarios.
	PhysicalName() *string
	// The stack in which this resource is defined.
	Stack() awscdk.Stack
	// Adds a new behavior to this distribution for the given pathPattern.
	AddBehavior(pathPattern *string, origin IOrigin, behaviorOptions *AddBehaviorOptions)
	// Apply the given removal policy to this resource.
	//
	// The Removal Policy controls what happens to this resource when it stops
	// being managed by CloudFormation, either because you've removed it from the
	// CDK application or because you've made a change that requires the resource
	// to be replaced.
	//
	// The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
	// account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
	ApplyRemovalPolicy(policy awscdk.RemovalPolicy)
	// Attach WAF WebACL to this CloudFront distribution.
	//
	// WebACL must be in the us-east-1 region.
	AttachWebAclId(webAclId *string)
	GeneratePhysicalName() *string
	// Returns an environment-sensitive token that should be used for the resource's "ARN" attribute (e.g. `bucket.bucketArn`).
	//
	// Normally, this token will resolve to `arnAttr`, but if the resource is
	// referenced across environments, `arnComponents` will be used to synthesize
	// a concrete ARN with the resource's physical name. Make sure to reference
	// `this.physicalName` in `arnComponents`.
	GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string
	// Returns an environment-sensitive token that should be used for the resource's "name" attribute (e.g. `bucket.bucketName`).
	//
	// Normally, this token will resolve to `nameAttr`, but if the resource is
	// referenced across environments, it will be resolved to `this.physicalName`,
	// which will be a concrete name.
	GetResourceNameAttribute(nameAttr *string) *string
	// Adds an IAM policy statement associated with this distribution to an IAM principal's policy.
	Grant(identity awsiam.IGrantable, actions ...*string) awsiam.Grant
	// Grant to create invalidations for this bucket to an IAM principal (Role/Group/User).
	GrantCreateInvalidation(identity awsiam.IGrantable) awsiam.Grant
	// Return the given named metric for this Distribution.
	Metric(metricName *string, props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 401.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric401ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 403.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric403ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 404.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric404ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx.
	// Default: - average over 5 minutes.
	//
	Metric4xxErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 502.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric502ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 503.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric503ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 504.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	Metric504ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 5xx.
	// Default: - average over 5 minutes.
	//
	Metric5xxErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.
	// Default: - sum over 5 minutes.
	//
	MetricBytesDownloaded(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.
	// Default: - sum over 5 minutes.
	//
	MetricBytesUploaded(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all cacheable requests for which CloudFront served the content from its cache.
	//
	// HTTP POST and PUT requests, and errors, are not considered cacheable requests.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	MetricCacheHitRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the total time spent from when CloudFront receives a request to when it starts providing a response to the network (not the viewer), for requests that are served from the origin, not the CloudFront cache.
	//
	// This is also known as first byte latency, or time-to-first-byte.
	//
	// To obtain this metric, you need to set `publishAdditionalMetrics` to `true`.
	// Default: - average over 5 minutes.
	//
	MetricOriginLatency(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.
	// Default: - sum over 5 minutes.
	//
	MetricRequests(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Metric for the percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.
	// Default: - average over 5 minutes.
	//
	MetricTotalErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric
	// Returns a string representation of this construct.
	ToString() *string
}

// The jsii proxy struct for Distribution
type jsiiProxy_Distribution struct {
	internal.Type__awscdkResource
	jsiiProxy_IDistribution
}

func (j *jsiiProxy_Distribution) DistributionArn() *string {
	var returns *string
	_jsii_.Get(
		j,
		"distributionArn",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) DistributionDomainName() *string {
	var returns *string
	_jsii_.Get(
		j,
		"distributionDomainName",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) DistributionId() *string {
	var returns *string
	_jsii_.Get(
		j,
		"distributionId",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) DistributionRef() *DistributionReference {
	var returns *DistributionReference
	_jsii_.Get(
		j,
		"distributionRef",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) DomainName() *string {
	var returns *string
	_jsii_.Get(
		j,
		"domainName",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) Env() *awscdk.ResourceEnvironment {
	var returns *awscdk.ResourceEnvironment
	_jsii_.Get(
		j,
		"env",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) Node() constructs.Node {
	var returns constructs.Node
	_jsii_.Get(
		j,
		"node",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) PhysicalName() *string {
	var returns *string
	_jsii_.Get(
		j,
		"physicalName",
		&returns,
	)
	return returns
}

func (j *jsiiProxy_Distribution) Stack() awscdk.Stack {
	var returns awscdk.Stack
	_jsii_.Get(
		j,
		"stack",
		&returns,
	)
	return returns
}


func NewDistribution(scope constructs.Construct, id *string, props *DistributionProps) Distribution {
	_init_.Initialize()

	if err := validateNewDistributionParameters(scope, id, props); err != nil {
		panic(err)
	}
	j := jsiiProxy_Distribution{}

	_jsii_.Create(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		[]interface{}{scope, id, props},
		&j,
	)

	return &j
}

func NewDistribution_Override(d Distribution, scope constructs.Construct, id *string, props *DistributionProps) {
	_init_.Initialize()

	_jsii_.Create(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		[]interface{}{scope, id, props},
		d,
	)
}

// Creates a Distribution construct that represents an external (imported) distribution.
func Distribution_FromDistributionAttributes(scope constructs.Construct, id *string, attrs *DistributionAttributes) IDistribution {
	_init_.Initialize()

	if err := validateDistribution_FromDistributionAttributesParameters(scope, id, attrs); err != nil {
		panic(err)
	}
	var returns IDistribution

	_jsii_.StaticInvoke(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		"fromDistributionAttributes",
		[]interface{}{scope, id, attrs},
		&returns,
	)

	return returns
}

// Checks if `x` is a construct.
//
// Use this method instead of `instanceof` to properly detect `Construct`
// instances, even when the construct library is symlinked.
//
// Explanation: in JavaScript, multiple copies of the `constructs` library on
// disk are seen as independent, completely different libraries. As a
// consequence, the class `Construct` in each copy of the `constructs` library
// is seen as a different class, and an instance of one class will not test as
// `instanceof` the other class. `npm install` will not create installations
// like this, but users may manually symlink construct libraries together or
// use a monorepo tool: in those cases, multiple copies of the `constructs`
// library can be accidentally installed, and `instanceof` will behave
// unpredictably. It is safest to avoid using `instanceof`, and using
// this type-testing method instead.
//
// Returns: true if `x` is an object created from a class which extends `Construct`.
func Distribution_IsConstruct(x interface{}) *bool {
	_init_.Initialize()

	if err := validateDistribution_IsConstructParameters(x); err != nil {
		panic(err)
	}
	var returns *bool

	_jsii_.StaticInvoke(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		"isConstruct",
		[]interface{}{x},
		&returns,
	)

	return returns
}

// Returns true if the construct was created by CDK, and false otherwise.
func Distribution_IsOwnedResource(construct constructs.IConstruct) *bool {
	_init_.Initialize()

	if err := validateDistribution_IsOwnedResourceParameters(construct); err != nil {
		panic(err)
	}
	var returns *bool

	_jsii_.StaticInvoke(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		"isOwnedResource",
		[]interface{}{construct},
		&returns,
	)

	return returns
}

// Check whether the given construct is a Resource.
func Distribution_IsResource(construct constructs.IConstruct) *bool {
	_init_.Initialize()

	if err := validateDistribution_IsResourceParameters(construct); err != nil {
		panic(err)
	}
	var returns *bool

	_jsii_.StaticInvoke(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		"isResource",
		[]interface{}{construct},
		&returns,
	)

	return returns
}

func Distribution_PROPERTY_INJECTION_ID() *string {
	_init_.Initialize()
	var returns *string
	_jsii_.StaticGet(
		"aws-cdk-lib.aws_cloudfront.Distribution",
		"PROPERTY_INJECTION_ID",
		&returns,
	)
	return returns
}

func (d *jsiiProxy_Distribution) AddBehavior(pathPattern *string, origin IOrigin, behaviorOptions *AddBehaviorOptions) {
	if err := d.validateAddBehaviorParameters(pathPattern, origin, behaviorOptions); err != nil {
		panic(err)
	}
	_jsii_.InvokeVoid(
		d,
		"addBehavior",
		[]interface{}{pathPattern, origin, behaviorOptions},
	)
}

func (d *jsiiProxy_Distribution) ApplyRemovalPolicy(policy awscdk.RemovalPolicy) {
	if err := d.validateApplyRemovalPolicyParameters(policy); err != nil {
		panic(err)
	}
	_jsii_.InvokeVoid(
		d,
		"applyRemovalPolicy",
		[]interface{}{policy},
	)
}

func (d *jsiiProxy_Distribution) AttachWebAclId(webAclId *string) {
	if err := d.validateAttachWebAclIdParameters(webAclId); err != nil {
		panic(err)
	}
	_jsii_.InvokeVoid(
		d,
		"attachWebAclId",
		[]interface{}{webAclId},
	)
}

func (d *jsiiProxy_Distribution) GeneratePhysicalName() *string {
	var returns *string

	_jsii_.Invoke(
		d,
		"generatePhysicalName",
		nil, // no parameters
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) GetResourceArnAttribute(arnAttr *string, arnComponents *awscdk.ArnComponents) *string {
	if err := d.validateGetResourceArnAttributeParameters(arnAttr, arnComponents); err != nil {
		panic(err)
	}
	var returns *string

	_jsii_.Invoke(
		d,
		"getResourceArnAttribute",
		[]interface{}{arnAttr, arnComponents},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) GetResourceNameAttribute(nameAttr *string) *string {
	if err := d.validateGetResourceNameAttributeParameters(nameAttr); err != nil {
		panic(err)
	}
	var returns *string

	_jsii_.Invoke(
		d,
		"getResourceNameAttribute",
		[]interface{}{nameAttr},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Grant(identity awsiam.IGrantable, actions ...*string) awsiam.Grant {
	if err := d.validateGrantParameters(identity); err != nil {
		panic(err)
	}
	args := []interface{}{identity}
	for _, a := range actions {
		args = append(args, a)
	}

	var returns awsiam.Grant

	_jsii_.Invoke(
		d,
		"grant",
		args,
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) GrantCreateInvalidation(identity awsiam.IGrantable) awsiam.Grant {
	if err := d.validateGrantCreateInvalidationParameters(identity); err != nil {
		panic(err)
	}
	var returns awsiam.Grant

	_jsii_.Invoke(
		d,
		"grantCreateInvalidation",
		[]interface{}{identity},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric(metricName *string, props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricParameters(metricName, props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric",
		[]interface{}{metricName, props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric401ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric401ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric401ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric403ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric403ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric403ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric404ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric404ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric404ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric4xxErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric4xxErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric4xxErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric502ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric502ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric502ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric503ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric503ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric503ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric504ErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric504ErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric504ErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) Metric5xxErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetric5xxErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metric5xxErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricBytesDownloaded(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricBytesDownloadedParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricBytesDownloaded",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricBytesUploaded(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricBytesUploadedParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricBytesUploaded",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricCacheHitRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricCacheHitRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricCacheHitRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricOriginLatency(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricOriginLatencyParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricOriginLatency",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricRequests(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricRequestsParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricRequests",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) MetricTotalErrorRate(props *awscloudwatch.MetricOptions) awscloudwatch.Metric {
	if err := d.validateMetricTotalErrorRateParameters(props); err != nil {
		panic(err)
	}
	var returns awscloudwatch.Metric

	_jsii_.Invoke(
		d,
		"metricTotalErrorRate",
		[]interface{}{props},
		&returns,
	)

	return returns
}

func (d *jsiiProxy_Distribution) ToString() *string {
	var returns *string

	_jsii_.Invoke(
		d,
		"toString",
		nil, // no parameters
		&returns,
	)

	return returns
}

