package cn.hztech.sdk.api;

import cn.hztech.sdk.client.SdkHttpClient;
import cn.hztech.sdk.model.PageResult;
import cn.hztech.sdk.model.entity.Role;
import cn.hztech.sdk.model.request.RoleDetailRequest;
import cn.hztech.sdk.model.request.RoleListRequest;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j;

/**
 * 角色管理API客户端
 *
 * 提供以下接口：
 * - getDetail: 查询角色详情
 * - getList: 角色列表查询
 */
@Slf4j
public class RoleApiClient {

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

    private final SdkHttpClient httpClient;

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

    /**
     * 查询角色详情
     *
     * @param roleId 角色ID
     * @return 角色信息
     */
    public Role getDetail(String roleId) {
        log.info("查询角色详情, roleId: {}", roleId);
        RoleDetailRequest request = new RoleDetailRequest();
        request.setRoleId(roleId);
        return httpClient.post(API_PREFIX + "/detail", request, Role.class);
    }

    /**
     * 查询角色列表
     *
     * @param request 查询请求
     * @return 分页结果
     */
    public PageResult<Role> getList(RoleListRequest request) {
        log.info("查询角色列表, request: {}", request);
        return httpClient.post(API_PREFIX + "/list", request, new TypeReference<PageResult<Role>>() {});
    }
}
