package com.xhpc.evcs.cdjgpc.api;

import com.xhpc.evcs.api.NotificationChargeOrderInfoController;
import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.utils.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.io.IOException;

/**
 * @author yuyang
 * @date 2023-09-24 19:15
 */
public class CDNotificationChargeOrderInfoController {

    private final Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoController.class);
    /**
     * 推送充电订单信息
     * @param commonRequest
     * @return
     * @throws IOException
     */
    @PostMapping("/v10/notification_charge_order_info")
    public CommonResponse notificationChargeOrderInfo(@RequestBody CommonRequest<CDChargeOrderInfo4BonusReq> commonRequest) throws IOException {
        String operatorID = commonRequest.getOperatorId();
        StationInfo stationInfo = new StationInfo();
        stationInfo.setOperatorId(operatorID);
        String data = commonRequest.getData();
        ChargeOrderInfo chargeOrderInfo = JSONUtil.readParams(data, ChargeOrderInfo.class);
        chargeOrderInfo.setInfraOperatorId("MA6CC2LK7"); //todo use common request operator id && check NPE
        chargeOrderInfo.setBillerOperatorId("MA6DFCTD5");
       // log.info(">>notify charge order OID: " + operatorID);
//        chargeOrderInfoRepository.save(chargeOrderInfo);
        CommonResponse response = new CommonResponse();
        response.setRet(EvcsConst.RET_SUCC);
        CDChargeOrder4BonusInfoRes resp = new CDChargeOrder4BonusInfoRes();
        resp.setConfirmResult(0);
        resp.setConnectorID(chargeOrderInfo.getConnectorID());
        resp.setStartChargeSeq(chargeOrderInfo.getStartChargeSeq());
        response.setData(JSONUtil.toJSONString(resp));
        return response;
    }

}
