import { UserBody } from '../models';

enum ActionKey {

  EMPLOYEE_LIST_RECEIVED = 'EMPLOYER/EMPLOYEE_LIST_RECEIVED',

  EMPLOYEE_DETAILS_REQUEST = 'EMPLOYER/EMPLOYEE_DETAILS_REQUEST',
  EMPLOYEE_DETAILS_SUCCESS = 'EMPLOYER/EMPLOYEE_DETAILS_SUCCESS',
  EMPLOYEE_DETAILS_FAIL = 'EMPLOYER/EMPLOYEE_DETAILS_FAIL',
}

export type EmployeeDetailsRequest = {
  type: ActionKey.EMPLOYEE_DETAILS_REQUEST;
  employeeId: string,
};
export function employeeDetailsRequest(employeeId: string): EmployeeDetailsRequest {
  return {
    type: ActionKey.EMPLOYEE_DETAILS_REQUEST,
    employeeId,
  };
}

export type EmployeeDetailsSuccess = {
  type: ActionKey.EMPLOYEE_DETAILS_SUCCESS;
  user: UserBody,
};
export function employeeDetailsSuccess(user: UserBody): EmployeeDetailsSuccess {
  return {
    type: ActionKey.EMPLOYEE_DETAILS_SUCCESS,
    user,
  };
}

export type EmployeeDetailsFailed = {
  type: ActionKey.EMPLOYEE_DETAILS_FAIL;
  error: string,
};
export function employeeDetailsFail(error: string): EmployeeDetailsFailed {
  return {
    type: ActionKey.EMPLOYEE_DETAILS_FAIL,
    error,
  };
}

export type EmployeeListReceived = {
  type: ActionKey.EMPLOYEE_LIST_RECEIVED;
  employees: Array<UserBody>,
};
export function employeeListReceived(employees: Array<UserBody>): EmployeeListReceived {
  return {
    type: ActionKey.EMPLOYEE_LIST_RECEIVED,
    employees,
  };
}

type ActionType = EmployeeDetailsSuccess
  | EmployeeDetailsSuccess
  | EmployeeDetailsFailed
  | EmployeeListReceived;

export { ActionKey, ActionType };
