package customization

import (
	"netease_control_center/globals"
	"netease_control_center/interfaces/log"
)

const (
	Oem_Not             = 0
	Oem_ZhejiangTelecom = 1
	Oem_ChinaTelecom    = 2
	Oem_Yaduo           = 3
)

//true:ready to use, false: unready to ues
func OemCheck(trigUpdate bool) (bool, string) {
	switch globals.OemManufature {
	case Oem_ChinaTelecom:
		return true, ""

	case Oem_ZhejiangTelecom:
		if globals.OemManufactureCheckOk == true {
			return true, ""
		} else {
			//check fail
			if trigUpdate {
				go DoCheck(5)
			}
			return false, GetVui()
		}

	default:
		return true, ""
	}

	return false, "OEM权限审核未通过"
}

func GetVui() string {
	switch globals.OemManufature {
	case 1:
		//telecom
		return telecom_vui
	default:
		return ""
	}
}

func DoCheck(tryTimes int) error {
	if globals.OemManufature == 0 {
		return nil
	}
	switch globals.OemManufature {
	case Oem_ChinaTelecom:
		return nil
	case Oem_ZhejiangTelecom:
		ChinaTelecomReport()
		//telecom
		var tmp TelecomReqBody
		tmp.Init()
		curTry := 0
	telecomloop:
		if rsp := tmp.Post(); rsp.Err == nil {
			if rsp.Code == 0 {
				globals.OemManufactureCheckOk = true
			} else {
				globals.OemManufactureCheckOk = false
			}
		} else {
			globals.OemManufactureCheckOk = false
			log.Printf(log.ErrorLog, "Check err:%+v, try:%d\n", rsp, curTry)

			if curTry++; curTry < tryTimes {
				goto telecomloop
			}
			log.Println(log.DebugLog, "Try many times, still error, check fail!")
			return rsp.Err
		}
	}

	return nil
}

func AfterInternetConnectCheckOem() {
	switch globals.OemManufature {
	case Oem_ChinaTelecom:
		ChinaTelecomReport()
	default:

	}
}
