import PlaybackDevice from "./playback-device.js";
import User from "./user.js";
import Integration from "./integration.js";

const Serializer = (function () {
  function deserializeUser(object) {
    object.isAdmin = object.is_admin;
    return new User(object);
  }

  function deserializeUsers(objects) {
    return objects.map((object) => deserializeUser(object));
  }

  function deserializeDevice(object) {
    return new PlaybackDevice(object);
  }

  function deserializeDevices(objects) {
    if (!objects) return [];
    return objects.map((object) => deserializeDevice(object));
  }

  function deserializeIntegration(object) {
    return new Integration(object);
  }

  function deserializeIntegrations(objects) {
    if (!objects) return [];
    return objects.map((object) => deserializeIntegration(object));
  }

  return {
    deserializeUser,
    deserializeUsers,
    deserializeDevice,
    deserializeDevices,
    deserializeIntegration,
    deserializeIntegrations,
  };
})();

export default Serializer;
