package com.microservices.system.api.factory;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.domain.R;
import com.microservices.system.api.RemoteCmsService;
import com.microservices.system.api.domain.SysDept;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 内容管理服务降级处理
 *
 * @author microservices
 */
@Component
public class RemoteCmsFallbackFactory implements FallbackFactory<RemoteCmsService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteCmsFallbackFactory.class);

    @Override
    public RemoteCmsService create(Throwable throwable) {
        log.error("Cms服务调用失败:{}", throwable.getMessage());
        return new RemoteCmsService() {


            @Override
            public R<Boolean> changeUserRole(Long userId, Long oldDeptId, Long newDeptId, Long oldRoleId, Long newRoleId, String source) {
                return R.fail("修改用户在GitLInk项目中的权限失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getCmsCountByDeptId(Long deptId, String source) {
                return R.fail("通过组织Id获取专区下文章数量失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getCmsDocVisitsByDeptId(Long deptId, String source) {
                return R.fail("通过组织Id获取专区下文章阅读数量失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> getNotAuditCmsCountByDeptId(Long deptId, String source) {
                return R.fail("通过组织Id获取专区下待审核文章数量失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getProjectByDeptId(Long deptId, String source) {
                return R.fail("通过组织id获取专区对应项目失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> autoAddZoneCmsProjectByDept(Long deptId, String source) {
                return R.fail("新增特色专区时自动创建GitLink项目失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> autoUpdateZoneCmsProjectByDept(SysDept dept, String source) {
                return R.fail("修改组织时自动更新GitLink项目失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> autoOperateZoneCmsProjectWhenAuditStatusChangedByDept(String userName, String identifier, Long deptId, String operationType, String source) {
                return R.fail("专区审核设置发生变化时自动处理项目分支保护设置失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> initCmsDir(Long zoneId, Object cmsDirInput, String source) {
                return R.fail("初始化栏目失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> initCmsDoc(Long dirId, Object cmsDocInputDto, String source) {
                return R.fail("初始化文章失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> removeByDeptId(Long deptId, String source) {
                return R.fail("删除专区项目失败:" + throwable.getMessage());
            }

            @Override
            public R<JSONObject> selectCmsDocJSONObjectById(Long cmsDocId, String source) {
                return R.fail("获取文章JSON对象失败:" + throwable.getMessage());
            }
        };
    }
}
