package com.cool.store.controller.webb;

import com.cool.store.entity.EnterpriseUserDO;
import com.cool.store.enums.UserRoleEnum;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.SysRoleService;
import com.cool.store.service.UserAuthMappingService;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/pc/sysRole")
@Api(tags = "角色信息")
@Slf4j
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @Resource
    private UserAuthMappingService userAuthMappingService;

    @GetMapping(path = "/getXfsgRoles")
    public ResponseResult<Map<String, Long>> getXfsgRoles() {
        return ResponseResult.success(sysRoleService.getXfsgRoles());
    }

    @GetMapping(path = "/getUserIdByRegionIdWithRolePriority")
    public ResponseResult<String> getUserIdByRegionIdWithRolePriority(@RequestParam(value = "regionId", required = true) Long regionId) {
        List<UserRoleEnum> roleList = Arrays.asList(UserRoleEnum.THEATER_MANAGER, UserRoleEnum.OPERATIONS_MANAGER, UserRoleEnum.REGION_MANAGER);
        return ResponseResult.success(sysRoleService.getUserIdByRegionIdWithRolePriority(regionId, roleList));
    }

    @GetMapping(path = "/getUserByRoleEnumAndRegionId")
    @ApiOperation("获取有区域权限和职位")
    public ResponseResult<EnterpriseUserDO> getUserByRoleEnumAndRegionId(@RequestParam("regionId") Long regionId, @RequestParam("roleName") String roleName) {
        UserRoleEnum userRoleEnum = UserRoleEnum.getByDesc(roleName);
        return ResponseResult.success(userAuthMappingService.getUserByRoleEnumAndRegionId(userRoleEnum, regionId));
    }
}
