import {
  Body,
  Controller,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Put,
} from '@nestjs/common';
import { MerchanttypeService } from './merchanttype.service';
import { MerchantType } from './merchanttype.entity';
import { MessagePattern } from '@nestjs/microservices';

@Controller()
export class MerchanttypeController {
  constructor(private readonly merchantTypeDbService: MerchanttypeService) {}

  @MessagePattern({ cmd: 'merchant_type_get_all' })
  async getAll(): Promise<MerchantType[]> {
    return await this.merchantTypeDbService.getAll();
  }

  @MessagePattern({ cmd: 'merchant_type_get_by_id' })
  async getById(data: { id: number }): Promise<MerchantType> {
    const { id } = data;
    return await this.merchantTypeDbService.getById(id);
  }

  @MessagePattern({ cmd: 'merchant_type_add' })
  async createMerchantType(data: { body: any }): Promise<any> {
    const { body } = data;
    return await this.merchantTypeDbService.createMerchantType(body);
  }

  @MessagePattern({ cmd: 'merchant_type_update' })
  async updateMerchantType(data: { id: number; body: any }): Promise<any> {
    const { id, body } = data;
    return await this.merchantTypeDbService.updateMerchantType(id, body);
  }
}
