package clt_client

import (
	"bytes"
	"errors"
	"io"
	"lc/common/mqtt"
	"net/http"
)

// SwitchProgram 切换节目
func (c cltClient) SwitchProgram(m mqtt.Message, baseurl string) {
	var p ProgramInfo
	m.PayloadJSON(&p)
	url := baseurl + "vsns/sources/lan/vsns/" + p.Name + ".vsn/activated"
	request, err := http.NewRequest("PUT", url, nil)
	if err != nil {
		return
	}
	request.Header.Set("Accept", "application/json")
	_, err = c.HttpClient.Do(request)
	if err != nil {
		return
	}
}

// brightness
func (c cltClient) CommonPut(payload []byte, url string) error {
	var r io.Reader
	if payload == nil {
		return errors.New("func CommonPut error PUT操作消息体不能为空!")
	} else {
		r = bytes.NewReader(payload)
	}
	req, _ := http.NewRequest("PUT", url, r)
	req.Header.Add("Content-Type", "application/json")
	c.HttpClient.Do(req)
	return nil
}
