package com.samsung.embo.common.util.controller;

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

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.samsung.authentication.Account;
import com.samsung.embo.common.util.UtilService;
import com.samsung.role.RoleService;
import com.samsung.role.entity.UserRole;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

@RestController
@RequestMapping("/embo/util/")
public class UtilController {
	private final RoleService roleService;
	private final UtilService utilService;

	public UtilController(UtilService utilService, RoleService roleService) {
		this.utilService = utilService;
		this.roleService = roleService;
	}

	// com.samsung.role.controller userRoleInfo 참조
	@Operation(summary = "RoleInfo 조회")
	@GetMapping("roles")
	public List<UserRole> roles() throws Exception {

		return roleService.getUserRoleList(Account.currentUser().getUserId());
	}

	@Operation(summary = "Division 조회")
	@GetMapping("division")
	public List<Map<String, Object>> division() throws Exception {

		return utilService.selectDivision();
	}

	@Operation(summary = "RoleInfo 조회")
	@GetMapping("userInfo")
	public Map<String, Object> userInfo() throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		String userId = Account.currentUser().getUserId();
		result.put("role", roleService.getUserRoleList(userId));
		result.put("division", utilService.getUserDivision(userId));

		return result;
	}

	@Operation(summary = "my GroupMember 조회")
	@GetMapping("myGroupMember")
	public List<Map<String, Object>> myGroupMember() throws Exception {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", Account.currentUser().getUserId());
		return utilService.selectGroupMember(params);
	}

	@Operation(summary = "GroupMember by groupId 조회")
	@GetMapping("groupMember/{groupId}")
	public List<Map<String, Object>> groupMember(@Parameter(description = "group ID") @PathVariable String groupId) throws Exception {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("groupId", Account.currentUser().getUserId());
		return utilService.selectGroupMember(params);
	}
}
