package com.ruoyi.erp.request;

import com.alibaba.fastjson2.JSONObject;

import java.util.Collection;

/**
 * 查询商品规格请求（仅多规格商品）
 *
 * 对应接口：POST /api/open/product/sku/list
 * 请求体字段：
 * - product_id（必填）：管家商品ID数组，最多100个
 */
public class ProductSkuListQueryRequest extends ERPRequestBase {
	public ProductSkuListQueryRequest(IERPAccount erpAccount) {
		super("https://open.goofish.pro/api/open/product/sku/list", erpAccount);
	}

	/**
	 * 设置商品ID数组（必填，最多100个）
	 */
	public void setProductIds(long... productIds) {
		if (productIds == null || productIds.length == 0) {
			throw new IllegalArgumentException("productIds不能为空");
		}
		if (productIds.length > 100) {
			throw new IllegalArgumentException("productIds数量不能超过100");
		}
		ensureRequestBodyInitialized();
		this.requestBody.put("product_id", productIds);
	}

	/**
	 * 设置商品ID集合（必填，最多100个）
	 */
	public void setProductIds(Collection<Long> productIds) {
		if (productIds == null || productIds.isEmpty()) {
			throw new IllegalArgumentException("productIds不能为空");
		}
		if (productIds.size() > 100) {
			throw new IllegalArgumentException("productIds数量不能超过100");
		}
		long[] ids = new long[productIds.size()];
		int i = 0;
		for (Long id : productIds) {
			ids[i++] = id == null ? 0L : id;
		}
		setProductIds(ids);
	}

	private void ensureRequestBodyInitialized() {
		if (this.requestBody == null) {
			this.requestBody = new JSONObject();
		}
	}
}


