package clt_client

import (
	"github.com/sirupsen/logrus"
	"io/ioutil"
	"lc/common/mqtt"
	"net/http"
)

func (c cltClient) DelPrograms(m mqtt.Message, baseurl string) {
	var ps []ProgramInfo
	m.PayloadJSON(&ps)
	for _, v := range ps {
		url := baseurl + "vsns/sources/lan/vsns/" + v.Name + ".vsn"
		request, err := http.NewRequest("DELETE", url, nil)
		if err != nil {
			logrus.Errorf("NewRequest出错:%v", err)
			return
		}
		resp, err := c.HttpClient.Do(request)
		if err != nil {
			logrus.Errorf("http错误:%v", err)
			return
		}
		defer resp.Body.Close()
		ioutil.ReadAll(resp.Body)
	}
}

func (c cltClient) CleanAll(baseurl string) {
	url := baseurl + "clrprgms"
	request, err := http.NewRequest("DELETE", url, nil)
	if err != nil {
		logrus.Errorf("NewRequest出错:%v", err)
		return
	}
	resp, err := c.HttpClient.Do(request)
	if err != nil {
		logrus.Errorf("http错误%v", err)
		return
	}
	defer resp.Body.Close()
	ioutil.ReadAll(resp.Body)
}
