package com.xhpc.evcs.api;

import com.xhpc.evcs.dto.*;
import com.xhpc.evcs.encryption.EvcsConst;
import com.xhpc.evcs.notification.NotificationChargeOrderInfoTask;
import com.xhpc.evcs.utils.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Slf4j
@RestController()
public class NotificationChargeOrderInfoController {

    private final Logger logger = LoggerFactory.getLogger(NotificationChargeOrderInfoController.class);
    /**
     * 推送充电订单信息
     * @param commonRequest
     * @return
     * @throws IOException
     */
    @PostMapping("/v1/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("759588065"); //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;
    }

}
