package com.yonge.cooleshow.website.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("${app-config.url.website:}/website")
@Api(value = "官网", tags = "官网")
public class WebSiteController extends BaseController {
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "切换用户类型")
    @GetMapping("/cutUserType")
    public HttpResponseResult<String> cutUserType(
            @ApiParam(value = "userType", required = true) @RequestParam("userType") String userType) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return HttpResponseResult.failed(HttpStatus.FORBIDDEN, "请登录");
        }
        if(user.getUserType().contains(userType)){
            return HttpResponseResult.succeed(userType);
        }else{
            return HttpResponseResult.failed("没有该用户类型");
        }
    }

}