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

package pposRequest

import (
	"PPOSUtils/utils"
	"errors"
	"net/url"
)

//new...
func (that *PPOSClient) NewOrderPaymentWayList() *OrderPaymentWayListRequest {
	return &OrderPaymentWayListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgPaymentWay/list",
		},
	}
}

//Response...
type OrderPaymentWayListResponse struct {
	PaymentWayCode    string `json:"payment_way_code"`
	PaymentWayId      int64  `json:"payment_way_id"`
	PaymentWayLogo    string `json:"payment_way_logo"`
	PaymentWayLogoUrl string `json:"payment_way_logo_url"`
	PaymentWayName    string `json:"payment_way_name"`
	PaymentWayType    int64  `json:"payment_way_type"`
	PaymentWayTypeStr string `json:"payment_way_type_str"`
	Status            int64  `json:"status"`
	StatusStr         string `json:"status_str"`
}

//Request...
type OrderPaymentWayListRequest struct {
	Request
}

func (that *OrderPaymentWayListRequest) SetIsEnable(value int64) *OrderPaymentWayListRequest {
	that.initParams()
	that.params.Set("status", utils.ToString(value)) //后台开启的状态
	return that
}
func (that *OrderPaymentWayListRequest) SetIsShow(value int64) *OrderPaymentWayListRequest {
	that.initParams()
	that.params.Set("is_show", utils.ToString(value)) //微信开启的状态
	return that
}
func (that *OrderPaymentWayListRequest) SetIsVem(value int64) *OrderPaymentWayListRequest {
	that.initParams()
	that.params.Set("is_vem", utils.ToString(value)) //自助机开启的状态
	return that
}

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

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