package com.tofly.base.api.feign;

import com.tofly.base.api.feign.factory.AuthTokenServiceFallbackFactory;
import com.tofly.common.core.constant.SecurityConstants;
import com.tofly.common.core.entity.ResultRespone;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author Administrator
 * @date 2019/9/12  11:44
 */
@FeignClient(contextId = "authTokenService",value = "tofly-auth", fallbackFactory = AuthTokenServiceFallbackFactory.class)
public interface AuthTokenService {

    /**
     * 分页查询token 信息
     *
     * @param params 分页参数
     * @param from   内部调用标志
     * @return page
     */
    @PostMapping("/token/page")
    ResultRespone getTokenPage(@RequestBody Map<String, Object> params, @RequestHeader(SecurityConstants.FROM) String from);

    /**
     * 删除token
     *
     * @param token token
     * @param from  调用标志
     * @return
     */
    @DeleteMapping("/token/{token}")
    ResultRespone<Boolean> removeToken(@PathVariable("token") String token, @RequestHeader(SecurityConstants.FROM) String from);

    @RequestMapping(value = "/oauth/token", method=RequestMethod.POST)
    public ResponseEntity postAccessToken(Principal principal, @RequestParam
            Map<String, String> parameters) throws HttpRequestMethodNotSupportedException;

    @DeleteMapping("/token/remove")
    public ResultRespone<Boolean> removeTokenByUser(@RequestBody Map<String, Object> params, @RequestHeader(SecurityConstants.FROM) String from);
}
