package main

import (
	"flag"
	"fmt"
)

var (
	testURL        = flag.String("url", "http://192.168.0.160:8088", "login url")
	testProductKey = flag.String("productkey", "958daf8b3a533f0d9516ac8fd17ef0cb06b439e664787a2a89608a10eeee8eb3c35c82c505d19f8a4417e530de0678fd", "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
	}

}
