// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
//	http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package serviceconnect

import (
	"github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
)

// IngressConfig holds inbound listener details. For each endpoint exposed by a service connect task,
// there will be one inbound listener configured in the service connect container (to be precise, in the envoy proxy).
type IngressConfig struct {
	// ListenerPort is the port to which the envoy proxy will bind to.
	ListenerPort int64
	// InterceptPort is the port exposed by the application container.
	InterceptPort int64
	// ListenerName is the internal name used by AppNet for the listener.
	ListenerName string
}

// EgressConfig holds outbound listener details. There will be one outbound listener in each
// service connect container (to be precise, in the envoy proxy). All service connect enabled traffic
// from task application containers should pass through the outbound listener.
type EgressConfig struct {
	// ListenerName is the internal name used by AppNet for the listener.
	ListenerName string
	// CIDR range used to identify outbound service connect traffic.
	IPV4CIDR string
	IPV6CIDR string
	// ListenerPort is the port to which all traffic addressed to the CIDR range
	// will be redirected to. This port is never specified in the SC payload and
	// will always be generated by Fargate agent.
	ListenerPort int64
}

// ServiceConnectConfig will contain all service connect specific data associated with a particular task.
type ServiceConnectConfig struct {
	IngressConfigList []IngressConfig
	EgressConfig      EgressConfig
	DNSMappingList    []networkinterface.DNSMapping

	// StatsEndpoint is the path to the http endpoint from which service connect stats data is collected.
	StatsEndpoint string
	// ServiceConnectContainerName is the name of the special side container included in
	// service connect enabled tasks.
	ServiceConnectContainerName string
}
