/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		unphp <unphp@qq.com>
 * @date		2023-08-17
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

import (
	"errors"
	"net/url"
)

//new...
func (that *PPOSClient) NewMpGetByIds() *MpByIdsRequest {
	return &MpByIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/mp/getIds",
		},
	}
}

//Response...
type MpByIdsResponse struct {
	MpId     int64  `json:"mp_id"`
	MpName   string `json:"mp_name"`
	MpType   int64  `json:"mp_type"`
	MpHome   string `json:"mp_home"`
	MpDesc   string `json:"mp_desc"`
	IsEnable int64  `json:"is_enable"`
}

//Request...
type MpByIdsRequest struct {
	Request
}

func (that *MpByIdsRequest) SetMpIds(value string) *MpByIdsRequest {
	that.initParams()
	that.params.Set("mp_ids", value) //获取通过ids
	return that
}

//Params ...
func (that *MpByIdsRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

//Do ...
func (that *MpByIdsRequest) Do() ([]*MpByIdsResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.([]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	_rs := []*MpByIdsResponse{}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(MpByIdsResponse)
		if _err := that.ParseResponeMp(_tmp, _vData, false); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
