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

package pposRequest

import (
	"encoding/json"
	"errors"
	"net/url"
)

//NewCfgPaymentWayOpenList 获取支付方式
func (that *PPOSClient) NewCfgPaymentWayOpenList() *PaymentWayOpenListRequest {
	return &PaymentWayOpenListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgPaymentWay/openList",
		},
	}
}
func (that *PPOSClient) NewCfgPaymentWayAllList() *PaymentWayOpenListRequest {
	return &PaymentWayOpenListRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/cfgPaymentWay/allList",
		},
	}
}

type PaymentWayOpenListResponse struct {
	PaymentWayId   int64  `json:"payment_way_id"`
	PaymentWayName string `json:"payment_way_name"`
	PaymentWayCode string `json:"payment_way_code"`
}

//PaymentWayOpenListRequest
type PaymentWayOpenListRequest struct {
	Request
}

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

//Do ...
func (that *PaymentWayOpenListRequest) Do() ([]*PaymentWayOpenListResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_str, _err := json.Marshal(_data)
	if _err != nil {
		return nil, errors.New(that.apiAddress + _err.Error())
	}
	//返回结果
	_rs := make([]*PaymentWayOpenListResponse, 0)
	_err = json.Unmarshal(_str, &_rs)
	if _err != nil {
		return _rs, errors.New(that.apiAddress + _err.Error())
	}
	//
	return _rs, nil
}
