import { AvailableDays, Place } from "../../data/datasource/api/entities/place";
import { CategoryModelLan } from "./CategoryModel";

/**
 * Interface representing a place model.
 */
export interface PlaceModel {
  /** Unique identifier for the town */
  idTown: number;
  /** Unique identifier for the place */
  idPlace: number;
  /** Availability of the place */
  available: string;
  /** Description of the place */
  description: string;
  /** Latitude coordinate of the place */
  latitude: number;
  /** Longitude coordinate of the place */
  longitude: number;
  /** Image name associated with the place */
  imageName: string;
  /** Name of the place */
  name: string;
  /** Categories associated with the place */
  categories: CategoryModelLan[];
  /** Opening time of the place */
  openAt: number;
  /** Closing time of the place */
  closeAt: number;
  /** Optional start date for the place */
  startDate?: Date;
  /** Optional end date for the place */
  endDate?: Date;
  /** Address of the place */
  address: string;
}

/**
 * Converts a PlaceModel to a Place entity.
 * @param model - The PlaceModel to convert.
 * @returns The converted Place entity.
 */
export const placeModelToEntity = (model: PlaceModel): Place => {
  let availableDays = AvailableDays.WEEKEND;
  switch (model.available) {
    case AvailableDays.ALL_DAYS:
      availableDays = AvailableDays.ALL_DAYS;
      break;
    case AvailableDays.CUSTOM:
      availableDays = AvailableDays.CUSTOM;
      break;
    case AvailableDays.WEEKDAYS:
      availableDays = AvailableDays.WEEKDAYS;
      break;
    default:
      availableDays = AvailableDays.WEEKEND;
      break;
  }

  const place: Place = {
    idTown: model.idTown,
    idPlace: model.idPlace,
    available: availableDays,
    latitude: model.latitude,
    longitude: model.longitude,
    descriptions: [model.description],
    imagesList: [model.imageName],
    name: model.name,
    categoriesId: model.categories.map((category) => category.idCategory),
    openAt: model.openAt,
    closeAt: model.closeAt,
    startDate: model.startDate,
    endDate: model.endDate,
    address: model.address,
  };
  return place;
};
