#!/bin/sh
path="${0%/*}"
. "$path/inc.sh"

usage () {
	die 'gwmodem info'
}

while : ; do
	case "$1" in
		--)
			shift
			break
		;;
		-*)
			usage
		;;
		*)
			break
		;;
	esac
	shift
done

modemInfo() {
	# run one step of modemst script if modem.st.inc is missing
	: # TODO
}

simInfo() {
	APN= ; [ -e "${sim1conf}" ] && . "${sim1conf}"
	apn1="${APN:-not configured}"
	APN= ; [ -e "${sim2conf}" ] && . "${sim2conf}"
	apn2="${APN:-not configured}"
	sim1IN='-' ; sim1SEL='-'
	sim2IN='-' ; sim2SEL='-'
	if canSwitchSIM; then
		insertedSIM1 && sim1IN='INSERTED'
		insertedSIM2 && sim2IN='INSERTED'
		selectedSIM1 && sim1SEL='SELECTED' || sim2SEL='SELECTED'
	else
		apn2='not available'
	fi
	printf '+-------------------------:  SIM  :----------------------------\n'
	printf "| SIM1 = %-32s %-10s %-10s\n" "${apn1}" "${sim1IN}" "${sim1SEL}"
	printf "| SIM2 = %-32s %-10s %-10s\n" "${apn2}" "${sim2IN}" "${sim2SEL}"
}

run() {
	if modemNotInstalled; then
		echo "Modem is not installed"
		return
	fi
	modemInfo
	if modemConfigured; then
		simInfo
		/usr/local/bin/telem/modeminfo.sh
	else
		echo "| Modem is not configured"
	fi
	echo '+---------------------------------------------------------------'
}

run
