package com.reyun.saas.web.controller.common;

import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.common.restResult.ResultGenerator;
import com.reyun.saas.mob.user.service.AppService;
import com.reyun.saas.mob.user.service.ChannelService;
import com.reyun.saas.mob.user.service.UserService;
import com.reyun.saas.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @des 所有下拉框数据 查询类
 * @date
 */
@Slf4j
@Api(value = "/dropDown", tags = "所有下拉框数据 查询管理")
@ApiRestController("dropDown")
public class DropDownBoxController {
    @Autowired
    private UserService userServiceImpl;
    @Autowired
    private AppService appServiceImpl;
    @Autowired
    private ChannelService channelServiceImpl;


    @ApiOperation(value = "用户下拉框")
    @GetMapping("users")
    public RestResult getUser(){
        List<Map<String,Object>> userDTOs =userServiceImpl.findMyselfAndChSubordinate(SecurityUtils.getLoginUserId());
        return ResultGenerator.genSuccessResult(userDTOs);
    }

    @ApiOperation(value = "App下拉框")
    @GetMapping("app")
    public RestResult getApp(@RequestParam String os){
        List<Map<String,Object>> appDTOs =appServiceImpl.findAppsByUser(SecurityUtils.getLoginUserId(),os);
        return ResultGenerator.genSuccessResult(appDTOs);
    }

    @ApiOperation(value = "关联性App下拉框")
    @GetMapping("/join/app")
    public RestResult joinApp(String cid,@RequestParam String os){
        List<Map<String,Object>> appDTOs =appServiceImpl.findAppsByCid(SecurityUtils.getLoginUserId(),cid,os);
        return ResultGenerator.genSuccessResult(appDTOs);
    }
    @ApiOperation(value = "关联性渠道下拉框")
    @GetMapping("/join/channel")
    public RestResult joinChannel(String appkey,@RequestParam String os){
        List<Map<String,Object>> channelDTOs =channelServiceImpl.findChannelsByAppkey(SecurityUtils.getLoginUserId(),appkey,os);
        return ResultGenerator.genSuccessResult(channelDTOs);
    }
}
