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

const { ClickStatsResponseCodes } = responseCodes;

// POST: create click stat
export const createClickStats = catchAsync(async (req: Request, res: Response) => {
  const clickStat = await clickStatsService.createClickStats(req.body);

  res.success(
    clickStat,
    ClickStatsResponseCodes.SUCCESS,
    'ClickStats Created Successfully',
  );
});

// GET: get counts by type + propertyId
export const getClickStatsCounts = catchAsync(async (req: Request, res: Response) => {
  const filter = pick(req.query, ['type', 'propertyId']);

  const counts = await clickStatsService.getClickStatsCounts(filter);

  res.success(
    counts,
    ClickStatsResponseCodes.SUCCESS,
    'ClickStats Count Fetched Successfully',
  );
});
