package aws

import (
	apigatewaytypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types"

	model "security-center-backend/internal/modules/caasm/model"
)

func endpointExposure(isPublic bool) string {
	if isPublic {
		return "public"
	}
	return "private"
}

func endpointZoneType(isPublic bool) string {
	return endpointExposure(isPublic)
}

func setServiceEndpointDomainDefaults(domain *model.DomainAsset, service string, isPublic bool) {
	if domain == nil {
		return
	}
	domain.ZoneType = endpointZoneType(isPublic)
	if domain.Status == "" {
		domain.Status = "active"
	}
	if domain.DomainClass == "" {
		domain.DomainClass = model.DomainClassServiceHostname
	}
	if domain.Registrar == "" {
		domain.Registrar = service
	}
}

func isPrivateRESTAPIEndpoint(cfg *apigatewaytypes.EndpointConfiguration) bool {
	if cfg == nil {
		return false
	}
	for _, endpointType := range cfg.Types {
		if endpointType == apigatewaytypes.EndpointTypePrivate {
			return true
		}
	}
	return false
}
