package com.api.service.impl;

import com.api.service.DoudianTokenService;
import com.doudian.open.api.address_list.AddressListRequest;
import com.doudian.open.api.address_list.AddressListResponse;
import com.doudian.open.api.address_list.param.AddressListParam;
import com.doudian.open.core.AccessToken;
import com.doudian.open.core.AccessTokenBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class DoudianTokenServiceImpl implements DoudianTokenService {
    @Autowired
    AddressListRequest addressListRequest;
    private AccessToken accessToken;
    // zxy测试预填入Token
    @PostConstruct
    public void initToken() {
        accessToken = AccessTokenBuilder.refresh("3ce5a5db-bd29-471b-b7c1-1b277a760dbe");
    }
    @Override
    public AccessToken getShopAccessToken(Long shopId) {
        accessToken= AccessTokenBuilder.build(shopId);
        return null;
    }
    @Override
    public AddressListResponse getAddressList(Long shopId) {
        AddressListParam param = addressListRequest.getParam();
        param.setPageNo(1L);
        param.setPageSize(10L);
        param.setShopId(shopId);
        param.setOrderBy("desc");
        param.setOrderField("create_time");
        AddressListResponse execute = addressListRequest.execute(accessToken);
        return null;
    }
}
