import { Injectable } from '@angular/core';
import {
  BatchResponseArgsOfProductListItemDTOAndString,
  ListResponseArgsOfProductListItemDTO,
  ProductListItemDTO,
  ProductListService,
  QuerySettingsDTO,
  QueryTokenDTO,
  ResponseArgsOfProductListItemDTO,
  ResponseArgsOfQuerySettingsDTO,
} from '@generated/swagger/wws-api';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class DomainProductListService {
  constructor(private _productList: ProductListService) {}

  getQuerySettingsResponse(): Observable<ResponseArgsOfQuerySettingsDTO> {
    return this._productList.ProductListQueryProductListItemsSettings();
  }

  getQuerySettings(): Observable<QuerySettingsDTO> {
    return this.getQuerySettingsResponse().pipe(map((response) => response.result));
  }

  queryProductListResponse(queryToken: QueryTokenDTO): Observable<ListResponseArgsOfProductListItemDTO> {
    return this._productList.ProductListQueryProductListItem(queryToken);
  }

  queryProductList(queryToken: QueryTokenDTO): Observable<ProductListItemDTO[]> {
    return this.queryProductListResponse(queryToken).pipe(map((response) => response.result));
  }

  completeProductListItemResponse(productListItemUId: string): Observable<ResponseArgsOfProductListItemDTO> {
    return this._productList.ProductListProductListItemCompleted(productListItemUId);
  }

  completeProductListItem(productListItemUId: string): Observable<ProductListItemDTO> {
    return this.completeProductListItemResponse(productListItemUId).pipe(map((response) => response.result));
  }

  completeProductListItemsResponse(uids: string[]): Observable<BatchResponseArgsOfProductListItemDTOAndString> {
    return this._productList.ProductListProductListItemsCompleted(uids);
  }

  completeProductListItems(uids: string[]): Observable<BatchResponseArgsOfProductListItemDTOAndString> {
    return this.completeProductListItemsResponse(uids);
  }
}
