package com.ms.biz.spi.callback;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.SPIBaseService;
import com.ms.biz.dto.openspi.request.QuerySupplyPlatformAuthParam;
import com.ms.biz.dto.openspi.response.QuerySupplyPlatformAuthData;
import com.ms.biz.service.ShopService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@ExtensionService("querySupplyPlatformAuth")
@Slf4j
@AllArgsConstructor
public class QuerySupplyPlatformAuthService extends SPIBaseService implements ExtensionServiceHandler<QuerySupplyPlatformAuthParam, JSONObject> {
    private ShopService shopService;

    @Override
    public BaseResponse<JSONObject> handle(BaseRequest<QuerySupplyPlatformAuthParam> req) {
        try {
            QuerySupplyPlatformAuthParam param = req.getData();
            QuerySupplyPlatformAuthData data = new QuerySupplyPlatformAuthData();
            shopService.querySupplyPlatformAuth(param, data);
            return BaseResponse.<JSONObject>builder().success(true).message("success").code("0").data(JSON.parseObject(JSON.toJSONString(data))).build();
        } catch (RuntimeException e) {
            return BaseResponse.<JSONObject>builder().success(true).message(e.getMessage()).code("100003").build();
        } catch (Throwable e) {
            log.error("querySupplyPlatformAuth error", e);
            return BaseResponse.<JSONObject>builder().success(true).message("系统异常").code("100003").build();
        }
    }
}