import { Dispatch } from 'react';
import { ApiOkResponse, ApiErrorResponse } from 'apisauce';
<%_ if(features.loginandsignup) { _%>
import { CurrentUser } from '@interfaces/authInterfaces';
import { Nullable } from '@interfaces/globalInterfaces';
<%_ } _%>

export interface Action<T = null, P = null, K = null> {
  [key: string]: any;
  type: string;
  target?: string;
  payload?: T;
  key?: string;
  index?: number;
  service?: Function;
  injections?: any[];
  successSelector?: (response: ApiOkResponse<P>) => K;
  failureSelector?: (response: ApiErrorResponse<P>) => K;
}

export type DispatcheableAction<T = null, P = null, K = null> = (
  dispatch: Dispatch<Action<T, P, K>>,
  getState: () => State
) => void;

export interface AuthState {
  initialLoading: boolean;
  <%_ if(features.loginandsignup) { _%>
  currentUser: Nullable<CurrentUser>;
  currentUserLoading: boolean;
  currentUserError: Nullable<string>;
  <%_ } _%>
  <%_ if(features.onboarding) { _%>
  hasAccessOnBoarding: boolean;
  <%_ } _%>
}

export interface State {
  auth: AuthState;
}

export interface ReduxObject {
  getState: () => State;
}
