import { Controller, Get, Post, Patch, Delete, Body, Param, HttpCode, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { CurrenciesService } from './currencies.service';
import { CreateCurrencyDto, UpdateCurrencyDto } from './currencies.dto';
import { IamGuard, IamRoles } from '../../common/iam-adapter';

@ApiTags('Currencies')
@Controller('currencies')
export class CurrenciesController {
  constructor(private currenciesService: CurrenciesService) {}

  @Get()
  getAllCurrencies() {
    return this.currenciesService.getAllCurrencies();
  }

  @Post()
  @UseGuards(IamGuard)
  @IamRoles('ADMIN')
  @ApiBearerAuth('IAM-auth')
  @HttpCode(201)
  createCurrency(@Body() dto: CreateCurrencyDto) {
    return this.currenciesService.createCurrency(dto);
  }

  @Patch(':id')
  @UseGuards(IamGuard)
  @IamRoles('ADMIN')
  @ApiBearerAuth('IAM-auth')
  updateCurrency(@Param('id') id: string, @Body() dto: UpdateCurrencyDto) {
    return this.currenciesService.updateCurrency(id, dto);
  }

  @Delete(':id')
  @UseGuards(IamGuard)
  @IamRoles('ADMIN')
  @ApiBearerAuth('IAM-auth')
  deleteCurrency(@Param('id') id: string) {
    return this.currenciesService.deleteCurrency(id);
  }

  @Post('sync-rates')
  @UseGuards(IamGuard)
  @IamRoles('ADMIN')
  @ApiBearerAuth('IAM-auth')
  @HttpCode(200)
  syncRates() {
    return this.currenciesService.syncExchangeRates();
  }
}
