import { Settings } from '@backend/domain'
import { buildMapsUrl } from '@core/utils'
import { SettingsResponse, WidgetSettingsResponse } from '../types'

export class SettingsMapper {
	static entityToResponse(settings: Settings): SettingsResponse {
		return {
			customerApp: settings.customerApp,
			schedule: settings.schedule,
			reservation: settings.reservation,
			restaurant: settings.restaurant,
			features: settings.features,
			kitchen: settings.kitchen,
			emailTemplates: settings.emailTemplates,
			billing: settings.billing,
			email: settings.email,
		}
	}

	static entityToWidgetSettings(settings: Settings): WidgetSettingsResponse {
		return {
			displayName: settings.customerApp.displayName,
			logoUrl: settings.customerApp.logoUrl,
			bannerUrl: settings.customerApp.bannerUrl,
			defaultReservationTime: settings.reservation.defaultReservationTime,
			schedule: settings.schedule,
			restaurant: {
				email: settings.restaurant.email,
				phone: settings.restaurant.phone,
				address: settings.restaurant.address,
			},
			mapsUrl: buildMapsUrl(settings.restaurant.googlePlaceId, settings.restaurant.address),
		}
	}
}
