package main

import (
	"flag"
	"fmt"
)

var (
	testURL        = flag.String("url", "http://114.115.211.247:8082", "login url")
	testProductKey = flag.String("productkey", "0aa9eab3202fc0a0940923ae02174b2334da8b2a79b45a6f37b94404ee6dd96e33057e03cd7c7030c9a215f6a22d16ca", "product key")
	testProtocol   = flag.String("protocol", "mqtt", "access protocol")
	testDeviceCode = flag.String("dvc", "", "device code")
	confCAFile     = flag.String("certfile", "keys/cacert.pem", "ca-file")
	confKeyFile    = flag.String("pkeyfile", "keys/privkey.pem", "key file")
)

func main() {
	flag.Parse()
	if *testProductKey == "" {
		fmt.Println("product key not provided. use -productkey flag")
		return
	}

	dev := NewDevice(*testURL, *testProductKey, *testDeviceCode, "1.2.3", *testProtocol)

	err := dev.DoRegister()
	if err != nil {
		fmt.Printf("device register error %s", err)
		return
	}

	err = dev.DoLogin()
	if err != nil {
		fmt.Printf("device login error %s", err)
		return
	}
	err = dev.DoAccess()
	if err != nil {
		fmt.Printf("device access error %s", err)
		return
	}

}
