package cn.superdesk.uniorder.openapi.oauth2;

import cn.superdesk.uniorder.openapi.api.base.O;
import cn.superdesk.uniorder.openapi.oauth2.request.AccessTokenRequest;
import cn.superdesk.uniorder.openapi.oauth2.request.RefreshTokenRequest;
import cn.superdesk.uniorder.openapi.oauth2.response.AccessTokenResponse;
import cn.superdesk.uniorder.openapi.oauth2.response.RefreshTokenResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Api(value = "授权API接口", tags = {"授权API接口"})
@ApiSort(value = 100000)
@Slf4j
@RestController
@RequestMapping("/v0//oauth2")
public class Oauth2Controller {

	@ApiOperation(value = "获取AccessToken")
	@ApiOperationSupport(order = 10)
	@RequestMapping(value = "accessToken", method = RequestMethod.POST)
	@ResponseBody
	public O<AccessTokenResponse> accessToken(@RequestBody AccessTokenRequest request) {

		AccessTokenResponse accessTokenResponse = new AccessTokenResponse();

		return new O<AccessTokenResponse>()
				.setResult(accessTokenResponse)
				.setResultCode(200)
				.setResultMessage("成功")
				.setSuccess(true);
	}

	@ApiOperation(value = "刷新AccessToken")
	@ApiOperationSupport(order = 20)
	@RequestMapping(value = "refreshToken", method = RequestMethod.POST)
	@ResponseBody
	public O<RefreshTokenResponse> refreshToken(@RequestBody RefreshTokenRequest result) {

		RefreshTokenResponse refreshTokenResponse = new RefreshTokenResponse();

		return new O<RefreshTokenResponse>()
				.setResult(refreshTokenResponse)
				.setResultCode(200)
				.setResultMessage("成功")
				.setSuccess(true);
	}
}
