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.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 java.util.List;
import java.util.Map;

/**
 * @ClassName UserAuthMappingController
 * @Description 区域权限信息
 */
@RestController
@RequestMapping("/pc/userAuthMapping")
@Api(tags = "区域权限信息")
@Slf4j
public class UserAuthMappingController {

    @Autowired
    private UserAuthMappingService userAuthMappingService;


    @ApiOperation("找人")
    @GetMapping("/getUserByRoleNameAndAreaId")
    public ResponseResult<EnterpriseUserDO> getUserByRoleNameAndAreaId(@RequestParam(value = "roleName", required = true) String roleName,
                                                                  @RequestParam(value = "wantShopAreaId", required = true) Long wantShopAreaId) {
        UserRoleEnum roleEnum = UserRoleEnum.getByDesc(roleName);
        return ResponseResult.success(userAuthMappingService.getUserByRoleEnumAndWantShopAreaId(roleEnum, wantShopAreaId));
    }

    @ApiOperation("找意向区域")
    @GetMapping("/listWantShopAreaIdByUserId")
    public ResponseResult<List<Long>> listWantShopAreaIdByUserId(@RequestParam(value = "userId", required = true) String userId) {
        return ResponseResult.success(userAuthMappingService.listWantShopAreaIdByUserId(userId));
    }

    @ApiOperation("找角色下的人")
    @GetMapping("/getUserIdByRoleIdAndRegionId")
    public ResponseResult<Map<String, List<String>>> getUserIdByRoleIdAndRegionId(@RequestParam(value = "roleIds", required = true) List<String> roleIds,
                                                                                  @RequestParam(value = "regionId", required = true) Long regionId) {
        return ResponseResult.success(userAuthMappingService.getUserIdByRoleIdAndRegionId(roleIds, regionId));
    }

}
