import {
  Body,
  Controller,
  Get,
  Inject,
  Param,
  ParseIntPipe,
  Post,
  Put,
} from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';

@Controller('api/merchantcategorygateway')
export class MerchantcategorygatewayController {
  constructor(@Inject('MERCHANT_CATEGORY') private client: ClientProxy) {}

  @Get()
  async getAll() {
    console.log('ok calling!');
    return this.client.send({ cmd: 'merchant_category_get_all' }, {});
  }

  @Get(':id')
  async getById(@Param('id', ParseIntPipe) id: number) {
    return this.client.send({ cmd: 'merchant_category_getby_id' }, { id });
  }

  @Post()
  async createMerchantCategory(@Body() body: any) {
    return this.client.send({ cmd: 'merchant_category_add' }, { body });
  }

  @Put(':id')
  async updateMerchantCategory(
    @Param('id', ParseIntPipe) id: number,
    @Body() body: any,
  ) {
    console.log('ok2');
    console.log(id);
    console.log(body);
    return this.client.send({ cmd: 'merchant_category_update' }, { id, body });
  }
}
