package com.jsowell.web.controller.thirdparty;

import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.thirdparty.common.NotificationDTO;
import com.jsowell.thirdparty.common.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/thirdparty/notification")
public class ThirdPartyNotificationController extends BaseController {
    @Autowired
    private NotificationService notificationService;

    /**
     * 充电站信息变化推送
     */
    @PostMapping("/notificationStationInfo")
    public AjaxResult notificationStationInfo(@RequestBody NotificationDTO dto) {
        AjaxResult result;
        try {
            notificationService.notificationStationInfo(dto);
            result = AjaxResult.success();
        } catch (BusinessException e) {
            logger.error("充电站信息变化推送失败", e);
            result = AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("充电站信息变化推送失败", e);
            result = AjaxResult.error();
        }
        return result;
    }

    /**
     * 设备状态变化推送
     */
    @PostMapping("/notificationStationStatus")
    public AjaxResult notificationStationStatus(@RequestBody NotificationDTO dto) {
        AjaxResult result;
        try {
            notificationService.notificationStationStatus(dto);
            result = AjaxResult.success();
        } catch (BusinessException e) {
            logger.error("设备状态变化推送失败", e);
            result = AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("设备状态变化推送失败", e);
            result = AjaxResult.error();
        }
        return result;
    }

    /**
     * 设备充电中状态变化推送
     */
    @PostMapping("/notificationConnectorChargeStatus")
    public AjaxResult notificationConnectorChargeStatus(@RequestBody NotificationDTO dto) {
        AjaxResult result;
        try {
            notificationService.notificationConnectorChargeStatus(dto);
            result = AjaxResult.success();
        } catch (BusinessException e) {
            logger.error("设备充电中状态变化推送失败", e);
            result = AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("设备充电中状态变化推送失败", e);
            result = AjaxResult.error();
        }
        return result;
    }

    /**
     * 充电订单信息推送
     */
    @PostMapping("/notificationChargeOrderInfo")
    public AjaxResult notificationChargeOrderInfo(@RequestBody NotificationDTO dto) {
        AjaxResult result;
        try {
            notificationService.notificationChargeOrderInfo(dto);
            result = AjaxResult.success();
        } catch (BusinessException e) {
            logger.error("充电订单信息推送失败", e);
            result = AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("充电订单信息推送失败", e);
            result = AjaxResult.error();
        }
        return result;
    }

    /**
     * 站点费率变化推送
     */
    @PostMapping("/notificationStationFee")
    public AjaxResult notificationStationFee(@RequestBody NotificationDTO dto) {
        AjaxResult result;
        try {
            notificationService.notificationStationFee(dto);
            result = AjaxResult.success();
        } catch (BusinessException e) {
            logger.error("站点费率变化推送失败", e);
            result = AjaxResult.error(e.getMessage());
        } catch (Exception e) {
            logger.error("站点费率变化推送失败", e);
            result = AjaxResult.error();
        }
        return result;
    }
}
