import { Selector, createSelector } from '@ngrx/store';
import {
  AuthResponse,
  DeptInfo,
  UserInfoSS,
  DeptUserResponse
} from '@ucap-webmessenger/protocol-query';

export interface State {
  auth?: AuthResponse;

  departmentInfoList: DeptInfo[] | null;

  selectedDepartmentUserInfoList: UserInfoSS[] | null;
  selectedDepartmentStatus: DeptUserResponse | null;
  selectedDepartmentProcessing: boolean;
}

export const initialState: State = {
  auth: null,
  departmentInfoList: null,
  selectedDepartmentUserInfoList: null,
  selectedDepartmentStatus: null,
  selectedDepartmentProcessing: false
};

export function selectors<S>(selector: Selector<any, State>) {
  return {
    auth: createSelector(
      selector,
      (state: State) => state.auth
    ),
    departmentInfoList: createSelector(
      selector,
      (state: State) => state.departmentInfoList
    ),
    selectedDepartmentUserInfoList: createSelector(
      selector,
      (state: State) => state.selectedDepartmentUserInfoList
    ),
    selectedDepartmentStatus: createSelector(
      selector,
      (state: State) => state.selectedDepartmentStatus
    ),
    selectedDepartmentProcessing: createSelector(
      selector,
      (state: State) => state.selectedDepartmentProcessing
    )
  };
}
