package ppt2img

import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/rdlucklib/rdluck_tools/http"
	"eta/eta_api/utils"
)

type Ppt2ImgResponse struct {
	Ret         int
	Msg         string
	ErrMsg      string
	ErrCode     string
	Data        []string
	Success     bool `description:"true 执行成功，false 执行失败"`
	IsSendEmail bool `description:"true 发送邮件，false 不发送邮件"`
}

// Ppt2Img ppt转图片
// @params pptUrl ppt的在线url
func Ppt2Img(pptUrl string) (resourceUrlList []string, err error) {
	// ppt转图片的地址未配置的话，直接返回
	if utils.Ppt2ImageUrl == `` {
		return
	}
	params := make(map[string]interface{})
	params["PptUrl"] = pptUrl
	param, err := json.Marshal(params)
	if err != nil {
		utils.FileLog.Info("Ppt2Img json.Marshal Err:" + err.Error())
		return
	}

	body, err := http.Post(utils.Ppt2ImageUrl, string(param))
	var result Ppt2ImgResponse
	err = json.Unmarshal(body, &result)
	if err != nil {
		fmt.Println("err:" + err.Error())
		return
	}
	if result.Ret != 200 {
		err = errors.New("获取token失败，Err:" + result.Msg)
		return
	}
	resourceUrlList = result.Data
	return
}
