/// 재고 요약 목록 조회 필터.
class InventorySummaryFilter {
  const InventorySummaryFilter({
    this.page = 1,
    this.pageSize = 50,
    this.query,
    this.productName,
    this.vendorName,
    this.warehouseId,
    this.includeEmpty = false,
    this.updatedSince,
    this.sort,
    this.order,
  });

  final int page;
  final int pageSize;
  final String? query;
  final String? productName;
  final String? vendorName;
  final int? warehouseId;
  final bool includeEmpty;
  final DateTime? updatedSince;
  final String? sort;
  final String? order;

  /// API 요청에 사용할 쿼리 파라미터 맵을 생성한다.
  Map<String, dynamic> toQuery() {
    final queryMap = <String, dynamic>{'page': page, 'page_size': pageSize};
    void put(String key, dynamic value) {
      if (value == null) {
        return;
      }
      if (value is String) {
        final trimmed = value.trim();
        if (trimmed.isEmpty) {
          return;
        }
        queryMap[key] = trimmed;
        return;
      }
      queryMap[key] = value;
    }

    put('q', query);
    put('product_name', productName);
    put('vendor_name', vendorName);
    if (warehouseId != null) {
      queryMap['warehouse_id'] = warehouseId;
    }
    if (includeEmpty) {
      queryMap['include_empty'] = 'true';
    }
    if (updatedSince != null) {
      queryMap['updated_since'] = updatedSince!.toUtc().toIso8601String();
    }
    put('sort', sort);
    final normalizedOrder = order?.trim().toLowerCase();
    if (normalizedOrder != null && normalizedOrder.isNotEmpty) {
      queryMap['order'] = normalizedOrder;
    }
    return queryMap;
  }
}

/// 재고 단건 조회 필터.
class InventoryDetailFilter {
  const InventoryDetailFilter({this.warehouseId, this.eventLimit = 20});

  final int? warehouseId;
  final int eventLimit;

  Map<String, dynamic> toQuery() {
    final map = <String, dynamic>{'event_limit': eventLimit};
    if (warehouseId != null) {
      map['warehouse_id'] = warehouseId;
    }
    return map;
  }
}
