/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.api.controller;

import com.api.dao.TokenDao;
import com.api.service.DoudianTokenService;
import com.api.service.TokenService;
import com.common.utils.R;
import com.api.annotation.Login;
import com.api.annotation.LoginUser;
import com.api.entity.UserEntity;
import com.doudian.open.api.token_create.TokenCreateRequest;
import com.doudian.open.core.DoudianOpClient;
import com.doudian.open.core.GlobalConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 测试接口
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/api/api")
@Api(tags="测试接口")
public class ApiTestController extends AbsctactController {
    @Autowired
    ApplicationContext applicationContext;
    @Autowired
    BeanFactory beanFactory;
    @Autowired
    TokenDao tokenDao;
    @Autowired
    TokenService tokenService;
    @Autowired
    DoudianTokenService doudianTokenService;
    @Login
    @GetMapping("userInfo")
    @ApiOperation(value="获取用户信息", response=UserEntity.class)
    public R userInfo(@ApiIgnore @LoginUser UserEntity user){
        return R.ok().put("user", user);
    }

    @Login
    @GetMapping("userId")
    @ApiOperation("获取用户ID")
    public R userInfo(@ApiIgnore @RequestAttribute("userId") Integer userId){
        return R.ok().put("userId", userId);
    }

    @GetMapping("notToken")
    @ApiOperation("忽略Token验证测试")
    public R notToken(HttpServletRequest request, HttpSession httpSession){
        Object beanNamesForType = applicationContext.getBean(TokenDao.class);
        TokenDao bean = beanFactory.getBean(TokenDao.class);
        TokenDao tokenDao = (TokenDao) beanNamesForType;
//        return R.ok().put("msg", "无需token也能访问。。。");
        return R.ok().put( "无需token也能访问。。。");
    }

//    @GetMapping("notToken")
//    @ApiOperation("忽略Token验证测试")
//    public R createToken(HttpServletRequest request, HttpSession httpSession){
//        tokenService.testCreateToken(request);
////        return R.ok().put("msg", "无需token也能访问。。。");
//        return R.ok().put( "无需token也能访问。。。");
//    }


}
