package address_list_request

import (
	"encoding/json"
	address_list_response "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/address_list/response"
	doudian_sdk "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/core"
)

type AddressListRequest struct {
	doudian_sdk.BaseDoudianOpApiRequest
	Param *AddressListParam
}

func (c *AddressListRequest) GetUrlPath() string {
	return "/address/list"
}

func New() *AddressListRequest {
	request := &AddressListRequest{
		Param: &AddressListParam{},
	}
	request.SetConfig(doudian_sdk.GlobalConfig)
	request.SetClient(doudian_sdk.DefaultDoudianOpApiClient)
	return request

}

func (c *AddressListRequest) Execute(accessToken *doudian_sdk.AccessToken) (*address_list_response.AddressListResponse, error) {
	responseJson, err := c.GetClient().Request(c, accessToken)
	if err != nil {
		return nil, err
	}
	response := &address_list_response.AddressListResponse{}
	_ = json.Unmarshal([]byte(responseJson), response)
	return response, nil

}

func (c *AddressListRequest) GetParamObject() interface{} {
	return c.Param
}

func (c *AddressListRequest) GetParams() *AddressListParam {
	return c.Param
}

type AddressListParam struct {
	// 店铺id(字段废弃，不建议传入)
	ShopId int64 `json:"shop_id"`
	// 翻页每页数量，默认10
	PageSize int64 `json:"page_size"`
	// 翻页页数，从1开始
	PageNo int64 `json:"page_no"`
	// 排序方式支持asc/desc
	OrderBy string `json:"order_by"`
	// 排序字段
	OrderField string `json:"order_field"`
	// 门店ID（传入后只获取该门店下地址列表）
	StoreId int64 `json:"store_id"`
}
