package com.weaver.seconddev.chapanda.feishu.esb;

import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.seconddev.chapanda.feishu.util.Esb2FeishuDeleteCalendarTimeoffUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service("Esb2FeishuDeleteCalendarsTimeoffAction")
public class Esb2FeishuDeleteCalendarsTimeoffAction implements EsbServerlessRpcRemoteInterface {
    private final static Logger log = LoggerFactory.getLogger(Esb2FeishuDeleteCalendarsTimeoffAction.class);

    @Autowired
    Esb2FeishuDeleteCalendarTimeoffUtil esb2FeishuDeleteCalendarTimeoffUtil;

    @Override
    public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
        String timeoff_event_id = (String) params.get("timeoff_event_id");
        String datacode = (String) params.get("datacode");
        String dataid = (String) params.get("dataid");

        if("0".equals(datacode)){
            return WeaResult.fail(500,"请假日程已删除");
        }

        log.error("timeoff_event_id:{}",timeoff_event_id);

        if(StringUtils.isBlank(timeoff_event_id)){
            return WeaResult.fail(500,"获取请假日程为空");
        }

        String code = "";
        if(StringUtils.isNotBlank(timeoff_event_id)){
            code = esb2FeishuDeleteCalendarTimeoffUtil.deleteCalendarTimeOff(timeoff_event_id);
        }
        log.error("code:{}",code);

        if(!"0".equals(code)){
            return WeaResult.fail(500,"请假日历删除失败");
        }

        Map<String, Object> actionMap = new HashMap<String, Object>();
        actionMap.put("code",200);
        actionMap.put("msg","成功");
        actionMap.put("timeoffEventId",timeoff_event_id);
        actionMap.put("datacode",code);
        actionMap.put("dataid",dataid);
        return WeaResult.success(actionMap);
    }
}
