package com.tofly.base.api.feign.fallback;

import com.tofly.base.api.feign.AuthTokenService;
import com.tofly.common.core.entity.ResultRespone;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.HttpRequestMethodNotSupportedException;

import java.security.Principal;
import java.util.Map;

/**
 * @author Administrator
 * @date 2019/9/12  11:45
 */
@Slf4j
@Component
public class AuthTokenServiceFallbackImpl implements AuthTokenService {
    @Setter
    private Throwable cause;

    /**
     * 分页查询token 信息
     *
     * @param params 分页参数
     * @param from   内部调用标志
     * @return page
     */
    @Override
    public ResultRespone getTokenPage(Map<String, Object> params, String from) {
        log.error("调用认证中心查询token 失败", cause);
        return ResultRespone.failed("调用认证中心查询token 失败");
    }

    /**
     * 删除token
     *
     * @param s
     * @param id
     * @return
     */
    @Override
    public ResultRespone<Boolean> removeToken(String s, String id) {
        log.error("删除token 失败 {}", id, cause);
        return ResultRespone.failed("删除token 失败"+id);
    }

    @Override
    public ResponseEntity postAccessToken(Principal principal, Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {
        log.error("用户登陆失败{}", parameters, cause);
        return ResponseEntity.ok(cause);
    }

    @Override
    public ResultRespone<Boolean> removeTokenByUser(Map<String, Object> params,String from) {
        log.error("删除token 失败 :{}", params);
        return ResultRespone.failed("删除token 失败");
    }
}
