package com.sptg.permissions.api.feigns.fallback;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.PageBean;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.beans.ResultEnum;
import com.sptg.common.core.constant.OperationConstant;
import com.sptg.permissions.api.dto.OrgDto;
import com.sptg.permissions.api.entity.Organization;
import com.sptg.permissions.api.feigns.OrgFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

/**
 * title: OrgFeignFallback
 * package: com.sptg.permissions.api.feigns.fallback
 * description:
 *
 *
 *
 */
@Component
@Slf4j
public class OrgFeignFallback implements FallbackFactory<OrgFeign> {

    @Override
    public OrgFeign create(Throwable cause) {
        return new OrgFeign(){
            @Override
            public Organization getOrgById(Long id) {
                log.error(cause.getMessage(), cause);
                return null;
            }
            @Override
            public Page<Organization> pagingQuery(PageBean<Organization,OrgDto> pageBean) {
                log.error(cause.getMessage(), cause);
                return pageBean;
            }
            @Override
            public List<Organization> getSubListByPid(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>();
            }
            @Override
            public ResultBean<Boolean> updateIsEnable(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
            @Override
            public ResultBean<Boolean> deleteEntity(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
            @Override
            public List<Organization> selectListByLikeName(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>();
            }
            @Override
            public ResultBean<Organization> addEntity(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
            @Override
            public ResultBean<Boolean> editEntity(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
            @Override
            public ResultBean<Boolean> updatePid(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ResultBean<>(ResultEnum.ERROR);
            }
            @Override
            public List<Organization> selectListByCondition(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>();
            }
            @Override
            public Organization getOrgByCode(String code) {
                log.error(cause.getMessage(), cause);
                return null;
            }
            @Override
            public List<Organization> getListByIds(List<Long> idList) {
                log.error(cause.getMessage(), cause);
                return new ArrayList<>(OperationConstant.ZERO);
            }

            @Override
            public Integer selectCount(OrgDto dto) {
                log.error(cause.getMessage(), cause);
                return 0;
            }

            @Override
            public boolean updateEntity(Organization org) {
                log.error(cause.getMessage(), cause);
                return false;
            }

            @Override
            public Organization getByOldIdAndType(String oldId, String orgType) {
                log.error(cause.getMessage(), cause);
                return null;
            }

            @Override
            public boolean checkNameIsExist(String orgName) {
                log.error(cause.getMessage(), cause);
                return false;
            }
        };
    }
}
