import { createSelector } from '@ngrx/store';
import { selectShelfState } from '../shelf.selectors';
import { historyStateAdapter } from './history.state';
import { Dictionary } from '@ngrx/entity';
import { OrderHistory } from '../defs';

export const selectHistoryState = createSelector(selectShelfState, (s) => s.history);

export const { selectAll, selectEntities } = historyStateAdapter.getSelectors(selectHistoryState);

export const selectHistories = createSelector(selectEntities, (entities: Dictionary<OrderHistory>) => entities);

export const selectHistory = createSelector(
  selectEntities,
  (entities: Dictionary<OrderHistory>, id: number) => entities[id] && entities[id].histories
);

export const selectStatus = createSelector(
  selectEntities,
  (entities: Dictionary<OrderHistory>, id: number) => entities[id] && entities[id].status
);
