import { getUrl, getAuthTokenHeader } from "../helper";
import { authedFunction } from "../session";
export const eventActions = {
  addEvent: data => {
    const request = {
      method: "POST",
      url: getUrl("events", "add"),
      data: {
        event: data
      }
    };
    return authedFunction(request);
  },
  getEvents: (site, time) => {
    const query = {
      site
    };
    if (time) {
      query.time = time;
    }
    return authedFunction({
      method: "GET",
      url: getUrl("events", "get", query)
    });
  },
  getEvent: (site, id) => {
    const query = {
      site
    };
    return authedFunction({
      method: "GET",
      url: getUrl("events", `get/${id}`, query)
    });
  },
  getEventReps: (site, eventId) => {
    return authedFunction({
      method: "GET",
      url: getUrl("eventreps", "get", {
        site,
        eventId
      })
    });
  },
  getUserEventReps: async time => {
    const request = {
      method: "GET",
      url: getUrl("usereventreps", "get", time ? {
        time
      } : null),
      headers: {}
    };
    request.headers.authorization = await getAuthTokenHeader();
    return authedFunction(request);
  },
  getUpcomingUserEventReps: async (userId, time) => {
    const request = {
      method: "GET",
      url: getUrl("usereventreps", "getupcoming", {
        userId,
        time
      }),
      headers: {}
    };
    return authedFunction(request);
  },
  getSubmissions: async site => {
    return authedFunction({
      method: "GET",
      url: getUrl("events", "submissions/get", {
        site
      })
    });
  },
  handleEventSubmission: (site, id, action) => {
    return authedFunction({
      method: "POST",
      url: getUrl("events", "submissions/handle"),
      data: {
        site,
        id,
        action
      }
    });
  },
  getEventInvites: async () => {
    const request = {
      method: "GET",
      url: getUrl("eventinvites", "get"),
      headers: {}
    };
    request.headers.authorization = await getAuthTokenHeader();
    return authedFunction(request);
  },
  registerForEvent: async (site, userID, eventId, repId, count, notes, waitlistCount, user) => {
    const request = {
      method: "POST",
      url: getUrl("eventreps", "register"),
      data: {
        userID,
        eventId,
        repId,
        site,
        count,
        notes,
        waitlistCount,
        user
      }
    };
    return authedFunction(request);
  },
  removeEventAttendee: async (site, userID, eventId, repId) => {
    const request = {
      method: "POST",
      url: getUrl("eventreps", "remove"),
      data: {
        site,
        userID,
        eventId,
        repId
      },
      headers: {}
    };
    request.headers.authorization = await getAuthTokenHeader();
    return authedFunction(request);
  },
  addEventFeedback: async (site, userID, eventId, repId, feedback, rating) => {
    // deprecated
    return null;
  },
  sendEventInvite: async (site, userID, inviteId, eventId, repId) => {
    const request = {
      method: "POST",
      url: getUrl("eventinvites", "send"),
      data: {
        site,
        userID,
        inviteId,
        eventId,
        repId
      },
      headers: {}
    };
    request.headers.authorization = await getAuthTokenHeader();
    return authedFunction(request);
  },
  removeEventInvite: async (userID, site, eventId, repId) => {
    const request = {
      method: "POST",
      url: getUrl("eventinvites", "remove"),
      data: {
        site,
        eventId,
        repId
      },
      headers: {}
    };
    request.headers.authorization = await getAuthTokenHeader();
    return authedFunction(request);
  }
};
//# sourceMappingURL=eventActions.js.map