import {
  Body,
  Controller,
  Get,
  Inject,
  Injectable,
  Param,
  ParseIntPipe,
  Post,
  Put,
} from '@nestjs/common';
import { ClientProxy } from '@nestjs/microservices';

@Controller('api/merchanttype')
export class MerchanttypeController {
  constructor(@Inject('MERCHANT_TYPE') private client: ClientProxy) {}

  @Get()
  async getAll() {
    console.log('ok@23');
    return this.client.send({ cmd: 'merchant_type_get_all' }, {});
  }

  @Get(':id')
  async getById(@Param('id', ParseIntPipe) id: number) {
    return this.client.send({ cmd: 'merchant_type_get_by_id' }, { id });
  }

  @Post()
  async createMerchantType(@Body() body: any) {
    return this.client.send({ cmd: 'merchant_type_add' }, { body });
  }

  @Put(':id')
  async updateMerchantType(
    @Param('id', ParseIntPipe) id: number,
    @Body() body: any,
  ) {
    return this.client.send({ cmd: 'merchant_type_update' }, { id, body });
  }
}
