package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

type DeviceInfo struct {
	SeqNo     int    `json:"seq"`
	OrdNo     int64  `json:"ordNo"`
	SerialKey string `json:"serial_key"`
	CallNo    string `json:"call_no"`
	DLCIP     string `json:"dlc_ip"`
	RecIP     string `json:"rec_ip"`
}

func getDeviceInfo(callNo string) (*DeviceInfo, error) {
	fmt.Print("Getting device info...\n")
	fmt.Printf("url:%s\n", config.RestAPIGetDevice)

	url := fmt.Sprintf("%s?c=%s", config.RestAPIGetDevice, callNo)
	fmt.Println(url)

	resp, err := http.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	var deviceInfo DeviceInfo
	err = json.Unmarshal(body, &deviceInfo)
	if err != nil {
		return nil, err
	}

	return &deviceInfo, nil
}
