package cn.hztech.sdk.api;

import cn.hztech.sdk.client.SdkHttpClient;
import cn.hztech.sdk.model.entity.Menu;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 权限管理API客户端
 *
 * 提供以下接口：
 * - getUserMenu: 查询用户菜单
 * - getRoleMenu: 查询角色菜单
 */
@Slf4j
public class PermissionApiClient {

    private static final String API_PREFIX = "/hztech-application/permission";

    private final SdkHttpClient httpClient;

    public PermissionApiClient(SdkHttpClient httpClient) {
        this.httpClient = httpClient;
    }

    /**
     * 查询用户菜单
     *
     * @param userId 用户ID
     * @return 菜单列表
     */
    public List<Menu> getUserMenu(String userId) {
        log.info("查询用户菜单, userId: {}", userId);
        // 构建请求体
        String requestBody = "{\"userId\":\"" + userId + "\"}";
        return httpClient.post(API_PREFIX + "/user/menu", requestBody, new TypeReference<List<Menu>>() {});
    }

    /**
     * 查询角色菜单
     *
     * @param roleId 角色ID
     * @return 菜单列表
     */
    public List<Menu> getRoleMenu(String roleId) {
        log.info("查询角色菜单, roleId: {}", roleId);
        // 构建请求体
        String requestBody = "{\"roleId\":\"" + roleId + "\"}";
        return httpClient.post(API_PREFIX + "/role/menu", requestBody, new TypeReference<List<Menu>>() {});
    }
}
