import { Controller } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { LocationService } from './location.service';
import { MerchantLocation } from './location.entity';

@Controller()
export class LocationController {
  constructor(private readonly locationDbService: LocationService) {}

  @MessagePattern({ cmd: 'merchant_location_get_all' })
  async getAll(): Promise<MerchantLocation[]> {
    return await this.locationDbService.getAll();
  }

  @MessagePattern({ cmd: 'merchant_location_get_by_id' })
  async getById(data: { id: number }): Promise<MerchantLocation> {
    const { id } = data;
    return await this.locationDbService.getById(id);
  }

  @MessagePattern({ cmd: 'merchant_location_add' })
  async createMerchantLocation(data: { body: any }): Promise<any> {
    const { body } = data;
    return this.locationDbService.createMerchantLocation(body);
  }

  @MessagePattern({ cmd: 'merchant_location_update' })
  async updateLocation(data: { id: number; body: any }): Promise<any> {
    return await this.locationDbService.updateMerchantLocation(
      data.id,
      data.body,
    );
  }
}
