package djadcom_conv

import adcom1 "github.com/mxmCherry/openrtb/adcom1"

func DeviceType(device adcom1.DeviceType) int {
	var devicetype int

	if device == adcom1.DeviceMobile {
		devicetype = 1
	} else if device == adcom1.DevicePC {
		devicetype = 2
	} else if device == adcom1.DeviceTV {
		devicetype = 3
	} else if device == adcom1.DevicePhone {
		devicetype = 4
	} else if device == adcom1.DeviceTablet {
		devicetype = 5
	} else if device == adcom1.DeviceConnected {
		devicetype = 6
	} else if device == adcom1.DeviceSetTopBox {
		devicetype = 7
	} else if device == adcom1.DeviceOOH {
		devicetype = 8
	}
	return devicetype
}

func ConnectionType(conn adcom1.ConnectionType) int {
	var conntype int

	if conn == adcom1.ConnectionUnknown {
		conntype = 0
	} else if conn == adcom1.ConnectionEthernet {
		conntype = 1
	} else if conn == adcom1.ConnectionWIFI {
		conntype = 2
	} else if conn == adcom1.ConnectionCellular {
		conntype = 3
	} else if conn == adcom1.Connection2G {
		conntype = 4
	} else if conn == adcom1.Connection3G {
		conntype = 5
	} else if conn == adcom1.Connection4G {
		conntype = 6
	} else if conn == adcom1.Connection5G {
		conntype = 7
	}

	return conntype
}

func Linearity(linearity adcom1.LinearityMode) int {
	var linear int
	if linearity == adcom1.LinearityLinear {
		linear = 1
	} else {
		linear = 2
	}
	return linear
}

func Attribute(attr []int) []adcom1.CreativeAttribute {
	var attribute []adcom1.CreativeAttribute
	if len(attr) > 0 {
		for _, v := range attr {
			if v == 1 {
				attribute = append(attribute, adcom1.AttrAudioAuto)
			} else if v == 2 {
				attribute = append(attribute, adcom1.AttrAudioUser)
			} else if v == 3 {
				attribute = append(attribute, adcom1.AttrExpandableAuto)
			} else if v == 4 {
				attribute = append(attribute, adcom1.AttrExpandableUserClick)
			} else if v == 5 {
				attribute = append(attribute, adcom1.AttrExpandableUserRollover)
			} else if v == 6 {
				attribute = append(attribute, adcom1.AttrVideoAuto)
			} else if v == 7 {
				attribute = append(attribute, adcom1.AttrVideoUser)
			} else if v == 8 {
				attribute = append(attribute, adcom1.AttrPop)
			} else if v == 9 {
				attribute = append(attribute, adcom1.AttrProvocative)
			} else if v == 10 {
				attribute = append(attribute, adcom1.AttrExtremeAnimation)
			} else if v == 11 {
				attribute = append(attribute, adcom1.AttrSurvey)
			} else if v == 12 {
				attribute = append(attribute, adcom1.AttrTextOnly)
			} else if v == 13 {
				attribute = append(attribute, adcom1.AttrInteractive)
			} else if v == 14 {
				attribute = append(attribute, adcom1.AttrWindowsDialog)
			} else if v == 15 {
				attribute = append(attribute, adcom1.AttrHasAudioToggleButton)
			} else if v == 16 {
				attribute = append(attribute, adcom1.AttrHasSkipButton)
			} else if v == 17 {
				attribute = append(attribute, adcom1.AttrFlash)
			} else {
				attribute = append(attribute, adcom1.AttrResponsive)
			}
		}
	}
	return attribute
}

func APIFramework(apifw []adcom1.APIFramework) []int {
	var api []int
	if len(api) > 0 {
		for _, v := range apifw {
			if v == adcom1.APIVPAID10 {
				api = append(api, 1)
			} else if v == adcom1.APIVPAID20 {
				api = append(api, 2)
			} else if v == adcom1.APIMRAID10 {
				api = append(api, 3)
			} else if v == adcom1.APIORMMA {
				api = append(api, 4)
			} else if v == adcom1.APIMRAID20 {
				api = append(api, 5)
			} else if v == adcom1.APIMRAID30 {
				api = append(api, 6)
			} else if v == adcom1.APIOMID10 {
				api = append(api, 7)
			} else if v == adcom1.APISIMID10 {
				api = append(api, 8)
			} else {
				api = append(api, 9)
			}
		}
	}
	return api

}

func MediaProtocol(Protocol []adcom1.MediaCreativeSubtype) []int {

	var protocol []int

	if len(Protocol) > 0 {
		for _, v := range Protocol {
			if v == adcom1.CreativeVAST10 {
				protocol = append(protocol, 1)
			} else if v == adcom1.CreativeVAST20 {
				protocol = append(protocol, 2)
			} else if v == adcom1.CreativeVAST30 {
				protocol = append(protocol, 3)
			} else if v == adcom1.CreativeVAST10Wrapper {
				protocol = append(protocol, 4)
			} else if v == adcom1.CreativeVAST20Wrapper {
				protocol = append(protocol, 5)
			} else if v == adcom1.CreativeVAST30Wrapper {
				protocol = append(protocol, 6)
			} else if v == adcom1.CreativeVAST40 {
				protocol = append(protocol, 7)
			} else if v == adcom1.CreativeVAST40Wrapper {
				protocol = append(protocol, 8)
			} else if v == adcom1.CreativeDAAST10 {
				protocol = append(protocol, 9)
			} else if v == adcom1.CreativeDAAST10Wrapper {
				protocol = append(protocol, 10)
			} else if v == adcom1.CreativeVAST41 {
				protocol = append(protocol, 11)
			} else if v == adcom1.CreativeVAST41Wrapper {
				protocol = append(protocol, 12)
			} else if v == adcom1.CreativeVAST42 {
				protocol = append(protocol, 13)
			} else {
				protocol = append(protocol, 14)
			}
		}
	}

	return protocol
}