import { Request, Response } from 'express';
import catchAsync from '@/shared/utils/catchAsync';
import responseCodes from '@/shared/utils/responseCode/responseCode';
import { pick } from '@/shared/utils';
import { PaginateOptions } from '@/shared/utils/plugins/paginate/paginate';
import * as masterBankService from './bank.service';

const { MasterBankResponseCodes } = responseCodes;

export const getMasterBanks = catchAsync(async (req: Request, res: Response) => {
  const filter = pick(req.query, ['search']);
  const options: PaginateOptions = pick(req.query, [
    'sortBy',
    'limit',
    'page',
    'populate',
    'fields',
  ]);

  const result = await masterBankService.queryMasterBanks(filter, options);

  res.success(
    result,
    MasterBankResponseCodes.SUCCESS,
    'Banks fetched successfully',
  );
});

export const getMasterBankById = catchAsync(async (req: Request, res: Response) => {
  const { id } = pick(req.params, ['id']);
  const bank = await masterBankService.getMasterBankById(id);
  res.success(bank, MasterBankResponseCodes.SUCCESS, 'Bank fetched successfully');
});
