package com.trade.client.thirdparty;

import com.trade.service.contract.constant.ContractConstant;
import com.trade.service.contract.service.FddAccountService;
import com.trade.service.contract.service.SignPlatformService;
import com.trade.service.contract.util.fadada.dto.FaDaDaAuthCallback;
import com.trade.service.contract.util.fadada.dto.FaDaDaSignCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/fdd/callback")
public class FaDaDaCallbackController {

    private static final Logger logger = LoggerFactory.getLogger(FaDaDaCallbackController.class);
    @Resource
    private FddAccountService fddAccountService;
    @Resource(name = ContractConstant.CONTRACT_PLATFORM_SERVICE_NAME_FADADA)
    private SignPlatformService signPlatformService;

    @RequestMapping("/auth")
    public void authCallback(FaDaDaAuthCallback callback) {
        logger.info("fdd auth callback: {}", callback);
        boolean authStatus = "1".equals(callback.getAuthStatus());
        fddAccountService.updateAuthStatus(callback.getCustomerUserId(), authStatus);
    }


    @RequestMapping("/sign")
    public void signCallback(FaDaDaSignCallback callback) {
        logger.info("fdd sign callback: {}", callback);
        signPlatformService.handleCallback(callback);
    }
}
