import { Controller } from '@nestjs/common';
import { MerchantCategory } from './merchantcategory.entity';
import { MerchantcategoryService } from './merchantcategory.service';
import { MessagePattern } from '@nestjs/microservices';

@Controller()
export class MerchantcategoryController {
  constructor(
    private readonly merchantCategoryDbService: MerchantcategoryService,
  ) {}

  @MessagePattern({ cmd: 'merchant_category_get_all' })
  async getAll(): Promise<MerchantCategory[]> {
    return await this.merchantCategoryDbService.getAll();
  }

  @MessagePattern({ cmd: 'merchant_category_getby_id' })
  async getById(data: { id: number }): Promise<MerchantCategory> {
    const { id } = data;
    return await this.merchantCategoryDbService.getById(id);
  }
  @MessagePattern({ cmd: 'merchant_category_add' })
  async createMerchantCategory(data: { body: any }): Promise<any> {
    const { body } = data;
    return await this.merchantCategoryDbService.createMerchantCategory(body);
  }
  @MessagePattern({ cmd: 'merchant_category_update' })
  async updateMerchantCategory(data: { id: number; body: any }): Promise<any> {
    const { id, body } = data;
    console.log('in micro  id :', id);
    console.log('in micro  id :', body);
    return await this.merchantCategoryDbService.updateMerchantCategory(
      id,
      body,
    );
  }
}
