import PointType from "./pointsType";

class FullMapPointAddress {
  postal_code;
  city;
  street;
  building_number;
  locale_number;
  country = "Polska";

  constructor(init) {
    if (init !== undefined) {
      this.postal_code = init.postal_code == null ? "" : init.postal_code;
      this.city = init.city == null ? "" : init.city;
      this.street = init.street == null ? "" : init.street;
      this.building_number =
        init.building_number == null ? "" : init.building_number;
      this.locale_number = init.locale_number == null ? "" : init.locale_number;
      this.country = "Polska";
    }
  }
}

class FullMapPointOpenHours {
  day_of_week;
  open_from;
  open_to;

  constructor(init) {
    if (init !== undefined) {
      this.day_of_week = init.day_of_week;
      this.open_from = init.open_from;
      this.open_to = init.open_to;
    } else {
      this.day_of_week = null;
      this.open_from = null;
      this.open_to = null;
    }
  }
}

class FullMapPointsResponse {
  point_id;
  name;
  type;
  lat;
  lon;
  open_hours;
  address;
  description;
  clickHandler;

  constructor(init) {
    if (init !== undefined) {
      this.address = new FullMapPointAddress(init.address);
      this.lat = init.lat;
      this.lon = init.lon;
      this.point_id = init.point_id;
      this.name = init.name;
      this.description = init.description;
      if (init.type === "point") {
        this.type = PointType.Point;
      }
      if (init.type === "machine") {
        this.type = PointType.Machine;
      }
      if (init.type === "epaka") {
        this.type = PointType.Epaka;
      }
      if (init.open_hours.length) {
        this.open_hours = init.open_hours.map((el) => {
          return new FullMapPointOpenHours(el);
        });
      } else {
        this.open_hours = [];
      }
    } else {
      this.address = new FullMapPointAddress();
      this.open_hours = [];
    }
  }
}

export { FullMapPointOpenHours };
export default FullMapPointsResponse;
