package TaxSb

import (
	"encoding/json"
	"git.listensoft.net/tool/jspkit/common/lxhttp"
	"github.com/tidwall/gjson"
	"net/http"
)

// 我的待办结构体
type MyTaskSt struct {
	Name     string `json:"name"`      // 任务名称
	DeadLine string `json:"dead_line"` // 办理期限
	Status   string `json:"status"`    // 标签状态
}

// 获取我的待办信息方便进行对比
func GetMyTask(C *http.Client, BaseUrl string) ([]MyTaskSt, error) {
	myTaskList := []MyTaskSt{}
	Cookie := []*http.Cookie{}
	jsonData := map[string]interface{}{"Csbz": ""}
	headers := map[string]string{
		"Content-Type": "application/json",
		"User-Agent":   "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36",
		"accept":       "application/json;charset=UTF-8",
	}
	JsonR, _ := json.Marshal(jsonData)
	response, err := lxhttp.PostByteReader(C, BaseUrl+"/mhzx/api/mh/wddb/v1/wddbquerybbsmxx", JsonR, headers, Cookie)
	if err != nil {
		return nil, err
	}
	array := gjson.GetBytes(response, "Response.Data.wsbxxGrid").Array()
	for _, result := range array {
		myTaskList = append(myTaskList, MyTaskSt{
			Name:     result.Get("gnmc").String(),
			DeadLine: result.Get("sbqx").String(),
			Status:   result.Get("zt").String(),
		})
	}
	return myTaskList, nil
}
