package com.ms.biz.spi.auth;

import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.biz.common.R;
import com.ms.biz.common.Ret;
import com.ms.biz.common.SPIBaseService;
import com.ms.api.dto.auth.GetPlatformAuthUrlRequestDTO;
import com.ms.biz.service.DsApiService;
import com.ms.api.dto.dsapi.response.GetPlatformAuthUrlResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取授权1688地址
 * 抖店店铺未与任何1688账户绑定，可以通过当前连接获取与1688账户进行授权绑定
 */
@ExtensionService("getPlatformAuthUrl")
@Slf4j
public class GetPlatformAuthUrlService extends SPIBaseService implements ExtensionServiceHandler<GetPlatformAuthUrlRequestDTO, Ret> {

    @Autowired
    private DsApiService dsApiService;

    @Override
    public BaseResponse<Ret> handle(BaseRequest<GetPlatformAuthUrlRequestDTO> req) {
        try {
            initHandle(req);
            GetPlatformAuthUrlRequestDTO requestDTO = req.getData();
            GetPlatformAuthUrlResponseDTO responseDTO = dsApiService.getPlatformAuthUrl(shopInfo);
            Map<String, Object> data = new HashMap<>();
            data.put("redirectUrl", responseDTO.getRedirectUrl());
            return R.ok(Ret.success(data));
        } catch (Exception e) {

            log.error("getPlatformAuthUrl error：", e);
            return R.ok(Ret.fail(e.getMessage()));
        }
    }
}
