/*

Copyright (c) 2016, the flickelectricnz Go package authors

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

*/

package main

import (
	"flickelectricnz"
	"fmt"
	"os"
)

func main() {
	username := os.Getenv("FLICK_USERNAME")
	password := os.Getenv("FLICK_PASSWORD")

	if len(username) == 0 || len(password) == 0 {
		fmt.Fprintln(os.Stderr, "Missing FLICK_USERNAME/FLICK_PASSWORD environment variable")
		os.Exit(1)
	}

	auth, err := flickelectricnz.Login(username, password)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't log in: %s\n", err.Error())
		os.Exit(1)
	}

	needle, err := auth.GetPrice()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Couldn't retrieve price: %s\n", err.Error())
		os.Exit(1)
	}

	fmt.Printf("Price\t%f\nCommentary\t%s\nNeedlePosition\t%d\n", needle.PriceCents, needle.Commentary, needle.NeedlePosition)
	os.Exit(0)
}
