import { Request, Response } from 'express';
import catchAsync from '@/shared/utils/catchAsync';
import * as propertyUsageService from './propertyUsage.service';
import responseCodes from '@/shared/utils/responseCode/responseCode';
import { pick } from '@/shared/utils';

const { PropertyUsageResponseCodes } = responseCodes;

export const create = catchAsync(async (req: Request, res: Response) => {
  const result = await propertyUsageService.create(req.body);
  res.success(result, PropertyUsageResponseCodes.SUCCESS, 'PropertyUsage Created Successfully');
});

export const get = catchAsync(async (req: Request, res: Response) => {
  const result = await propertyUsageService.getById(req.params.id);
  res.success(result, PropertyUsageResponseCodes.SUCCESS, 'PropertyUsage Fetched Successfully');
});

export const update = catchAsync(async (req: Request, res: Response) => {
  await propertyUsageService.update(req.params.id, req.body);
  res.success(true, PropertyUsageResponseCodes.SUCCESS, 'PropertyUsage Updated Successfully');
});

export const remove = catchAsync(async (req: Request, res: Response) => {
  await propertyUsageService.remove(req.params.id);
  res.success(true, PropertyUsageResponseCodes.SUCCESS, 'PropertyUsage Deleted Successfully');
});

export const list = catchAsync(async (req: Request, res: Response) => {
  const filters = pick(req.query, [ 'search']);
  
    const options = pick(req.query, [
      'sortBy',
      'limit',
      'page',
      'populate',
      'fields',
    ]);
  
    const result = await propertyUsageService.queryPropertyUsage(
      filters,
      options,
    );
  res.success(result, PropertyUsageResponseCodes.SUCCESS, 'PropertyUsage Fetched Successfully');
});
