import { Application, ApplicationData, Offer, OfferBody } from '../models';

enum ActionKey {
  NEW_OFFER_REQUESTED = 'OFFER/NEW_OFFER_REQUESTED',
  UPDATE_OFFER_REQUESTED = 'OFFER/UPDATE_OFFER_REQUESTED',
  EDIT_OFFER_PHOTO = 'OFFER/EDIT_OFFER_PHOTO',
  NEW_OFFER_FAIL = 'OFFER/NEW_OFFER_FAIL',
  NEW_OFFER_SUCCESS = 'OFFER/NEW_OFFER_SUCCESS',
  UPDATE_OFFER_SUCCESS = 'OFFER/UPDATE_OFFER_SUCCESS',
  UPDATE_OFFER_FAIL = 'OFFER/UPDATE_OFFER_FAIL',

  DELETE_OFFER_REQUESTED = 'OFFER/DELETE_OFFER_REQUESTED',
  DELETE_OFFER_SUCCESS = 'OFFER/DELETE_OFFER_SUCCESS',
  DELETE_OFFER_FAIL = 'OFFER/DELETE_OFFER_FAIL',

  EMPLOYER_OFFERS_FETCH_SUCCESS = 'OFFER/EMPLOYER_OFFERS_FETCH_SUCCESS',
  EMPLOYEE_OFFERS_FETCH_SUCCESS = 'OFFER/EMPLOYEE_OFFERS_FETCH_SUCCESS',
  OFFERS_FETCH_FAIL = 'OFFER/OFFERS_FETCH_FAIL',
  NEW_APPLICATION_REQUEST = 'OFFER/NEW_APPLICATION_REQUEST',
  NEW_APPLICATION_SUCCESS = 'OFFER/NEW_APPLICATION_SUCCESS',
  NEW_APPLICATION_FAIL = 'OFFER/NEW_APPLICATION_FAIL',
  EMPLOYEE_APPLICATION_BODY_FETCHED = 'EMPLOYEE/EMPLOYEE_APPLICATION_BODY_FETCHED',
  EMPLOYER_APPLICATIONS_RECEIVED = 'EMPLOYER/EMPLOYER_APPLICATIONS_RECEIVED',

  APPLICATION_ACCEPTED_REQUESTED = 'OFFER/APPLICATION_ACCEPTED_REQUESTED',
  APPLICATION_ACCEPTED_SUCCESS = 'OFFER/APPLICATION_ACCEPTED_SUCCESS',
  APPLICATION_ACCEPTED_FAIL = 'OFFER/APPLICATION_ACCEPTED_FAIL',

  APPLICATION_REJECTED_REQUESTED = 'OFFER/APPLICATION_REJECTED_REQUESTED',
  APPLICATION_REJECTED_SUCCESS = 'OFFER/APPLICATION_REJECTED_SUCCESS',
  APPLICATION_REJECTED_FAIL = 'OFFER/APPLICATION_REJECTED_FAIL',

}
export type DeleteOfferRequested = {
  type: ActionKey.DELETE_OFFER_REQUESTED;
  offer: Offer,
};
export function DeleteOfferRequested(offer: Offer): DeleteOfferRequested {
  return {
    type: ActionKey.DELETE_OFFER_REQUESTED,
    offer,
  };
}

export type EditOfferPhoto = {
  type: ActionKey.EDIT_OFFER_PHOTO;
  offerId: string,
  photoPath: string;
};
export function editOfferPhoto(offerId: string, photoPath: string): EditOfferPhoto {
  return {
    type: ActionKey.EDIT_OFFER_PHOTO,
    offerId,
    photoPath,
  };
}

export type DeleteOfferSuccess = {
  type: ActionKey.DELETE_OFFER_SUCCESS;
  offerId: string,
};
export function DeleteOfferSuccess(offerId: string): DeleteOfferSuccess {
  return {
    type: ActionKey.DELETE_OFFER_SUCCESS,
    offerId,
  };
}
export type DeleteOfferFail = {
  type: ActionKey.DELETE_OFFER_FAIL;
  error: string,
  offerId: string,
};
export function DeleteOfferFail(offerId: string, error: string): DeleteOfferFail {
  return {
    type: ActionKey.DELETE_OFFER_FAIL,
    offerId,
    error,
  };
}

export type NewOfferRequest = {
  type: ActionKey.NEW_OFFER_REQUESTED;
  offer: OfferBody,
  photoPath?: string;
};
export function newOfferRequest(offer: OfferBody, photoPath?: string): NewOfferRequest {
  return {
    type: ActionKey.NEW_OFFER_REQUESTED,
    offer,
    photoPath,
  };
}
export type NewOfferSucccess = {
  type: ActionKey.NEW_OFFER_SUCCESS;
  offerId: string;
};
export function newOfferSuccess(offerId: string): NewOfferSucccess {
  return {
    type: ActionKey.NEW_OFFER_SUCCESS,
    offerId,
  };
}
export type NewOfferFail = {
  type: ActionKey.NEW_OFFER_FAIL;
  error: string,
};
export function newOfferFail(error: string): NewOfferFail {
  return {
    type: ActionKey.NEW_OFFER_FAIL,
    error,
  };
}

export type UpdateOfferRequest = {
  type: ActionKey.UPDATE_OFFER_REQUESTED;
  offer: Offer,
  photoPath?: string;
};
export function UpdateOfferRequest(offer: Offer, photoPath?: string): UpdateOfferRequest {
  return {
    type: ActionKey.UPDATE_OFFER_REQUESTED,
    offer,
    photoPath,
  };
}
export type UpdateOfferSuccess = {
  type: ActionKey.UPDATE_OFFER_SUCCESS;
  offerId: string;
};
export function UpdateOfferSuccess(offerId: string): UpdateOfferSuccess {
  return {
    type: ActionKey.UPDATE_OFFER_SUCCESS,
    offerId,
  };
}
export type UpdateOfferFail = {
  type: ActionKey.UPDATE_OFFER_FAIL;
  error: string,
};
export function UpdateOfferFail(error: string): UpdateOfferFail {
  return {
    type: ActionKey.UPDATE_OFFER_FAIL,
    error,
  };
}

export type EmployerOffersFetched = {
  type: ActionKey.EMPLOYER_OFFERS_FETCH_SUCCESS;
  offers: Array<Offer>,
};
export function EmployerOffersFetched(offers: Array<Offer>): EmployerOffersFetched {
  return {
    type: ActionKey.EMPLOYER_OFFERS_FETCH_SUCCESS,
    offers,
  };
}
export type EmployeeOffersFetched = {
  type: ActionKey.EMPLOYEE_OFFERS_FETCH_SUCCESS;
  offers: Array<Offer>,
};
export function EmployeeOffersFetched(offers: Array<Offer>): EmployeeOffersFetched {
  return {
    type: ActionKey.EMPLOYEE_OFFERS_FETCH_SUCCESS,
    offers,
  };
}

export type NewApplicationRequest = {
  type: ActionKey.NEW_APPLICATION_REQUEST;
  offer: Offer,
};
export function newApplicationRequest(offer: Offer): NewApplicationRequest {
  return {
    type: ActionKey.NEW_APPLICATION_REQUEST,
    offer,
  };
}

export type NewApplicationSuccess = {
  type: ActionKey.NEW_APPLICATION_SUCCESS;
  offerId: string;
};
export function newApplicationSuccess(offerId: string): NewApplicationSuccess {
  return {
    type: ActionKey.NEW_APPLICATION_SUCCESS,
    offerId,
  };
}

export type NewApplicationFail = {
  type: ActionKey.NEW_APPLICATION_FAIL;
  error: string,
  offerId: string,
};
export function newApplicationFail(offerId: string, error: string): NewApplicationFail {
  return {
    type: ActionKey.NEW_APPLICATION_FAIL,
    error,
    offerId,
  };
}

export type EmployeeApplicationFetched = {
  type: ActionKey.EMPLOYEE_APPLICATION_BODY_FETCHED;
  application: Application,
};
export function employeeApplicationFetched(application: Application): EmployeeApplicationFetched {
  return {
    type: ActionKey.EMPLOYEE_APPLICATION_BODY_FETCHED,
    application,
  };
}

export type EmployerApplicationsReceived = {
  type: ActionKey.EMPLOYER_APPLICATIONS_RECEIVED;
  applications: Array<ApplicationData>,
};
export function employerApplicationsReceived(applications: Array<ApplicationData>): EmployerApplicationsReceived {
  return {
    type: ActionKey.EMPLOYER_APPLICATIONS_RECEIVED,
    applications,
  };
}

export type ApplicationAcceptedRequested = {
  type: ActionKey.APPLICATION_ACCEPTED_REQUESTED;
  application: ApplicationData,
};
export function applicationAcceptedRequested(application: ApplicationData): ApplicationAcceptedRequested {
  return {
    type: ActionKey.APPLICATION_ACCEPTED_REQUESTED,
    application,
  };
}

export type ApplicationAcceptedSuccess = {
  type: ActionKey.APPLICATION_ACCEPTED_SUCCESS;
  application: ApplicationData,
};
export function applicationAcceptedSuccess(application: ApplicationData): ApplicationAcceptedSuccess {
  return {
    type: ActionKey.APPLICATION_ACCEPTED_SUCCESS,
    application,
  };
}

export type ApplicationAcceptedFail = {
  type: ActionKey.APPLICATION_ACCEPTED_FAIL;
  error: string,
};
export function ApplicationAcceptedFail(error: string): ApplicationAcceptedFail {
  return {
    type: ActionKey.APPLICATION_ACCEPTED_FAIL,
    error,
  };
}

export type ApplicationRejectedRequested = {
  type: ActionKey.APPLICATION_REJECTED_REQUESTED;
  application: ApplicationData,
};
export function applicationRejectedRequested(application: ApplicationData): ApplicationRejectedRequested {
  return {
    type: ActionKey.APPLICATION_REJECTED_REQUESTED,
    application,
  };
}

export type ApplicationRejectedSuccess = {
  type: ActionKey.APPLICATION_REJECTED_SUCCESS;
  application: ApplicationData,
};
export function applicationRejectedSuccess(application: ApplicationData): ApplicationRejectedSuccess {
  return {
    type: ActionKey.APPLICATION_REJECTED_SUCCESS,
    application,
  };
}

export type ApplicationRejectedFail = {
  type: ActionKey.APPLICATION_REJECTED_FAIL;
  error: string,
};
export function ApplicationRejectedFail(error: string): ApplicationRejectedFail {
  return {
    type: ActionKey.APPLICATION_REJECTED_FAIL,
    error,
  };
}

type ActionType = NewOfferRequest
  | EmployerOffersFetched
  | EmployeeOffersFetched
  | NewApplicationRequest
  | NewApplicationSuccess
  | NewApplicationFail
  | NewOfferSucccess
  | NewOfferFail
  | UpdateOfferRequest
  | UpdateOfferSuccess
  | UpdateOfferFail
  | ApplicationAcceptedRequested
  | ApplicationAcceptedSuccess
  | ApplicationAcceptedFail
  | ApplicationRejectedRequested
  | ApplicationRejectedSuccess
  | ApplicationRejectedFail
  | DeleteOfferRequested
  | DeleteOfferSuccess
  | DeleteOfferFail
  | EmployerApplicationsReceived
  | EditOfferPhoto
  | EmployeeApplicationFetched;

export { ActionKey, ActionType };
