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

const { LocationResponseCodes } = responseCodes;

export const create = catchAsync(async (req: Request, res: Response) => {
  const result = await locationService.create(req.params.type, req.body);
  res.success(result, LocationResponseCodes.SUCCESS, `${req.params.type} created successfully`);
});

export const get = catchAsync(async (req: Request, res: Response) => {
  const result = await locationService.getById(req.params.type, req.params.id);
  res.success(result, LocationResponseCodes.SUCCESS, `${req.params.type} fetched successfully`);
});

export const update = catchAsync(async (req: Request, res: Response) => {
  await locationService.update(req.params.type, req.params.id, req.body);
  res.success(true, LocationResponseCodes.SUCCESS, `${req.params.type} updated successfully`);
});

export const remove = catchAsync(async (req: Request, res: Response) => {
  await locationService.remove(req.params.type, req.params.id);
  res.success(true, LocationResponseCodes.SUCCESS, `${req.params.type} deleted successfully`);
});

export const list = catchAsync(async (req: Request, res: Response) => {
  const result = await locationService.list(req.params.type, req.query);
  res.success(result, LocationResponseCodes.SUCCESS, `${req.params.type}s listed successfully`);
});
