import { Selector } from '@ngxs/store';
import { ProcessStateModel, ProcessState } from '../state/process.state';
import { AppState, AppStateModel } from '../state/app.state';
import { ProductState, ProductStateModel } from '../state/product.state';

export class ProductSelectors {
  @Selector([AppState, ProductState])
  static getProducts(state: AppStateModel, productState: ProductStateModel) {
    const currentProcessId = state.currentProcesssId;

    return productState.products[currentProcessId];
  }

  @Selector([AppState, ProductState])
  static getCachedProducts(state: AppStateModel, productState: ProductStateModel) {
    const currentProcessId = state.currentProcesssId;

    return productState.cachedProductResults
      ? productState.cachedProductResults[currentProcessId]
        ? productState.cachedProductResults[currentProcessId].result
        : null
      : null;
  }
}
