import { Request, Response } from 'express';
import catchAsync from '@/shared/utils/catchAsync';
import responseCodes from '@/shared/utils/responseCode/responseCode.js';
import { createLocationHierarchyFromPlaceId } from './location.hierarchy.service.js';

const { LocationResponseCodes } = responseCodes;


export const createFromPlaceId = catchAsync(async (req: Request, res: Response) => {
  const { placeId } = req.body;
  const userId = req.user?.id;

  const result = await createLocationHierarchyFromPlaceId(placeId, userId);

  res.success({
    hierarchy: result.hierarchy,
    placeDetails: result.placeDetails,
  }, LocationResponseCodes.SUCCESS, 'Location hierarchy created successfully from Place ID');
});