package org.springblade.resource;

import org.springblade.modules.system.entity.VisualSubscribeNotifyConf;
import org.springblade.modules.system.enums.NotifyType;
import org.springblade.modules.system.service.impl.VisualSubscribeNotifyConfService;
import org.springblade.system.client.SubscribeNotifyConfClient;
import org.springblade.system.client.model.VisualSubscribeNotifyConfModel;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.List;

@RestController
@ApiIgnore
public class SubscribeNotifyConfResource implements SubscribeNotifyConfClient {

    @Autowired
    private VisualSubscribeNotifyConfService notifyConfService;

    @Override
    public List<VisualSubscribeNotifyConfModel> notifyConfList(Integer notifyType) {
        List<VisualSubscribeNotifyConfModel>result=new ArrayList<>();
        List<VisualSubscribeNotifyConf> confList =new ArrayList<>();
        if (notifyType == NotifyType.email.getValue()){
            confList = notifyConfService.notifyConfList(NotifyType.email);
        }else if (notifyType == NotifyType.qywechat.getValue()){
            confList = notifyConfService.notifyConfList(NotifyType.qywechat);
        }else if (notifyType == NotifyType.dingtalk.getValue()){
            confList = notifyConfService.notifyConfList(NotifyType.dingtalk);
        }else if (notifyType == NotifyType.feishu.getValue()){
            confList = notifyConfService.notifyConfList(NotifyType.feishu);
        }else if (notifyType == NotifyType.tianxiangyun.getValue()){
            confList = notifyConfService.notifyConfList(NotifyType.tianxiangyun);
        }
        for (VisualSubscribeNotifyConf conf : confList){
            VisualSubscribeNotifyConfModel model =new VisualSubscribeNotifyConfModel();
            BeanUtils.copyProperties(conf,model);
            result.add(model);
        }

        return result;
    }
    @Override
    public List<VisualSubscribeNotifyConfModel> newNotifyConfList(String tenantId,Integer notifyType) {
        List<VisualSubscribeNotifyConfModel>result=new ArrayList<>();
        List<VisualSubscribeNotifyConf> confList =new ArrayList<>();
        if (notifyType == NotifyType.email.getValue()){
            confList = notifyConfService.newNotifyConfList(tenantId,NotifyType.email);
        }else if (notifyType == NotifyType.qywechat.getValue()){
            confList = notifyConfService.newNotifyConfList(tenantId,NotifyType.qywechat);
        }else if (notifyType == NotifyType.dingtalk.getValue()){
            confList = notifyConfService.newNotifyConfList(tenantId,NotifyType.dingtalk);
        }else if (notifyType == NotifyType.feishu.getValue()){
            confList = notifyConfService.newNotifyConfList(tenantId,NotifyType.feishu);
        }else if (notifyType == NotifyType.tianxiangyun.getValue()){
            confList = notifyConfService.newNotifyConfList(tenantId,NotifyType.tianxiangyun);
        }
        for (VisualSubscribeNotifyConf conf : confList){
            VisualSubscribeNotifyConfModel model =new VisualSubscribeNotifyConfModel();
            BeanUtils.copyProperties(conf,model);
            result.add(model);
        }

        return result;
    }
}
