package provider

import (
	cloudv1 "github.com/tidbcloud/infra-api/api/v1"
)

const (
	replayTaintValue = "tidb-replay"
)

type replayCloudDefaults struct {
	zones   []string
	subnets []string
}

// deriveAWSReplayDefaults extracts replay runtime defaults from AWS subnet
// groups so the provider can write them back to the replay context explicitly.
func deriveAWSReplayDefaults(replay *cloudv1.Replay) replayCloudDefaults {
	if replay == nil {
		return replayCloudDefaults{}
	}
	if cloudaws := replay.Spec.Kubernetes.Cloud.AWS; cloudaws != nil {
		zones, subnets := cloudaws.SubnetGroups.SubnetsFilterByGroupNameOrZones([]cloudv1.AWSSubnetGroupName{
			cloudv1.AWSSubnetGroupNodes, cloudv1.AWSSubnetGroupSecondaryCIDR,
		}, []string{})
		return replayCloudDefaults{
			zones:   zones,
			subnets: subnets,
		}
	}
	return replayCloudDefaults{}
}

// deriveACKReplayDefaults extracts replay runtime defaults from ACK network
// settings so the provider can write them back to the replay context explicitly.
func deriveACKReplayDefaults(replay *cloudv1.Replay) replayCloudDefaults {
	if replay == nil {
		return replayCloudDefaults{}
	}
	if cloudack := replay.Spec.Kubernetes.Cloud.Ack; cloudack != nil {
		return replayCloudDefaults{
			subnets: cloudack.Subnets,
		}
	}
	return replayCloudDefaults{}
}
