import request from "@/api/request";

// 请求参数接口
export interface Request {
  keyword?: string;
  /**
   * 条数
   */
  limit?: string;
  pageSize?: string;
  /**
   * 分页
   */
  page?: string;
  [property: string]: any;
}

// ===== V2 API =====

/**
 * 获取流量池分组列表 (V2)
 * 用于获取流量池包/分组列表
 */
export function getPoolPackages(params: Request) {
  const v2Params = {
    page: params.page ? Number(params.page) : 1,
    pageSize: params.limit ? Number(params.limit) : (params.pageSize ? Number(params.pageSize) : 20),
    keyword: params.keyword || "",
  };
  return request("/v1/traffic/pool/v2/groups", v2Params, "GET");
}

/**
 * 获取流量池用户列表 (V2)
 */
export function getPoolList(params: {
  page?: string;
  pageSize?: string;
  keyword?: string;
  addStatus?: string;
  deviceId?: string;
  packageId?: string;
  groupId?: string;
  userValue?: string;
  [property: string]: any;
}) {
  const v2Params = {
    page: params.page ? Number(params.page) : 1,
    pageSize: params.pageSize ? Number(params.pageSize) : 20,
    keyword: params.keyword || "",
    groupId: params.groupId || params.packageId || "",
  };
  return request("/v1/traffic/pool/v2/group/members", v2Params, "GET");
}

/**
 * 删除流量池分组 (V2)
 */
export function deletePackage(id: number | string) {
  return request("/v1/traffic/pool/v2/group/delete", { groupId: id }, "DELETE");
}

/**
 * 创建流量池分组 (V2)
 */
export function createPackage(params: {
  name: string;
  description?: string;
  ruleType?: number;
  ruleConfig?: any;
}) {
  return request("/v1/traffic/pool/v2/group/create", {
    groupName: params.name,
    description: params.description || "",
    ruleType: params.ruleType || 0,
    ruleConfig: params.ruleConfig || null,
  }, "POST");
}

/**
 * 获取流量池分组详情 (V2)
 */
export function getPackageDetail(groupId: number | string) {
  return request("/v1/traffic/pool/v2/group/detail", { groupId }, "GET");
}
