import HelperUtil from '../../utils/HelperUtil'
import RailwayAPI from "../../api/restApis/RailwayAPI"
import {AREA_KEY,AREA_0,AREA_1} from "../../utils/constantCollection"

let staticMethods = {
  getAllRailwayCollection: function(){
    return RailwayAPI.getRailwayCollection().then(result => {
      if (result.data.result){
        return HelperUtil.arrayToObject(result.data.returnValue,AREA_KEY)
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  getAllRailwayAdminCollection: function(){
    return RailwayAPI.getRailwayAdminCollection().then(result => {
      if (result.data.result){
        return HelperUtil.arrayToObject(result.data.returnValue,AREA_0)
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },

  getAllRailwayDivisionCollection: function(){
    return RailwayAPI.getRailwayDivisionCollection().then(result => {
      if (result.data.result){
        return HelperUtil.arrayToObject(result.data.returnValue,AREA_1)
      }else{
        return HelperUtil.returnPromiseRejectObj(result);
      }
    });
  },
};

function RailwayService (websocketService = null){
  return Object.freeze(Object.assign(
    {

    },
    staticMethods
  ))
}

Object.assign(RailwayService, staticMethods);
export default RailwayService
