package netmgrd

import (
	modem1 "hnyfkj.com.cn/rtu/linux/air720u"
	"hnyfkj.com.cn/rtu/linux/baseapp"
	modem2 "hnyfkj.com.cn/rtu/linux/ec200u"
)

type ModemType int

const (
	Unknown ModemType = iota
	Air720U           // 合宙4G调制解调器, 注册网卡名为"eth2"
	EC200U            // 移远4G调制解调器, 注册网卡名为"usb0"
)

var (
	curModemType ModemType
)

const ErrUnknownModemTypeMsg = "未知的调制解调器类型" // ?

func (m ModemType) String() string {
	switch m {
	case Air720U:
		return "合宙"
	case EC200U:
		return "移远"
	default:
		return "未知"
	}
}

func ModemInit() bool {
	_ = baseapp.ExistsDir(baseapp.RUN_DIR, true) // 强容错

	if modem1.ModuleInit(false) {
		curModemType = Air720U
		return true
	}

	if modem2.ModuleInit(false) {
		curModemType = EC200U
		return true
	}

	return false
}

func ModemExit() {
	switch curModemType {
	case Air720U:
		modem1.ModuleExit()
	case EC200U:
		modem2.ModuleExit()
	}
}

func GetCurModemType() ModemType {
	return curModemType
}

func GetIMEI() string {
	switch curModemType {
	case Air720U:
		return modem1.GetIMEI()
	case EC200U:
		return modem2.GetIMEI()
	default:
		return ErrUnknownModemTypeMsg
	}
}

func GetRSSI() string {
	switch curModemType {
	case Air720U:
		return modem1.GetRSSI()
	case EC200U:
		return modem2.GetRSSI()
	default:
		return ErrUnknownModemTypeMsg
	}
}

func GetSimICCID() string {
	switch curModemType {
	case Air720U:
		return modem1.GetSimICCID()
	case EC200U:
		return modem2.GetSimICCID()
	default:
		return ErrUnknownModemTypeMsg
	}
}
