import { RPCClientError } from '@loafer/ng-rpc';

import { Sensor } from '@overflow/commons-typescript/model/sensor';
import { Selector, createSelector } from '@ngrx/store';
import { createEntityAdapter, EntityState } from '@loafer/ng-entity';
import { Page } from '@overflow/commons-typescript/model/commons/Page';

export const sensorListContainerAdapter = createEntityAdapter<Sensor, RPCClientError>();
export interface State extends EntityState<Sensor, RPCClientError> {
  page: Page<Sensor>;
  pending: boolean;
}
export const initialState: State = sensorListContainerAdapter.getInitialState({
  page: null,
  pending: false,
});

export function getSelectors(selector: Selector<any, State>) {
  return {
    ...sensorListContainerAdapter.getSelectors(selector),
    selectPending: createSelector(selector, (state: State) => state.pending),
    selectPage: createSelector(selector, (state: State) => {
      return state.page;
    })
  };
}
