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

package pposRequest

import (
	"errors"
	"net/url"
)

//new...
func (that *PPOSClient) NewSalesPointGetByIds() *SalesGetByIdsRequest {
	return &SalesGetByIdsRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/base/salesPoint/getByIds",
		},
	}
}

//Response...
type SalesGetByIdsResponse struct {
	PointId    int64  `json:"point_id"`
	BusinessId int64  `json:"business_id"`
	PointName  string `json:"point_name"`
	Status     string `json:"status"`
	Operator   string `json:"operator"`
}

//Request...
type SalesGetByIdsRequest struct {
	Request
}

func (that *SalesGetByIdsRequest) SetIds(value string) *SalesGetByIdsRequest {
	that.initParams()
	that.params.Set("ids", value) //营业点信息获取通过ids
	return that
}
func (that *SalesGetByIdsRequest) SetColumn(value string) *SalesGetByIdsRequest {
	that.initParams()
	that.params.Set("column", value) //字段名，逗号隔开
	return that
}

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

//Do ...
func (that *SalesGetByIdsRequest) Do() ([]*SalesGetByIdsResponse, 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 := []*SalesGetByIdsResponse{}
	for _, _v := range _sliceData {
		_vData, _ok := _v.(map[string]interface{})
		if !_ok {
			return nil, errors.New(that.apiAddress + "请求响应格式不正确2")
		}
		_tmp := new(SalesGetByIdsResponse)
		if _err := that.ParseResponeMp(_tmp, _vData, false); _err != nil {
			return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
		}
		_rs = append(_rs, _tmp)
	}
	return _rs, nil
}
