import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiParam, ApiSecurity } from '@nestjs/swagger';
import { ApiKeyGuard } from '../../common/guards/api-key.guard';
import { RequireApiTier } from '../../common/decorators/api-tier.decorator';
import { BlocksService } from './blocks.service';

@ApiTags('blocks')
@ApiSecurity('api-key')
@Controller('v1/blocks')
@UseGuards(ApiKeyGuard)
export class BlocksController {
  constructor(private readonly blocksService: BlocksService) {}

  @Get(':height')
  @RequireApiTier('public')
  @ApiOperation({ summary: '获取区块详情' })
  @ApiParam({ name: 'height', description: '区块高度' })
  getBlock(@Param('height') height: string) {
    return this.blocksService.getBlock(parseInt(height, 10));
  }
}
