import { Controller, Get, Post, Body } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { MigrationService } from './migration.service';
import { CurrentTenant } from '../../common/decorators/current-tenant.decorator';
import { CurrentUser } from '../../common/decorators/current-user.decorator';

@ApiTags('migration')
@ApiBearerAuth()
@Controller('migration')
export class MigrationController {
  constructor(private readonly migrationService: MigrationService) {}

  @Post('export')
  @ApiOperation({ summary: 'Export server configuration' })
  async exportConfig(
    @CurrentTenant() licenseId: string,
    @CurrentUser('sub') userId: string,
    @Body('export_type') exportType?: string,
  ) {
    return this.migrationService.exportConfig(licenseId, userId, exportType || 'full');
  }

  @Get('exports')
  @ApiOperation({ summary: 'Get export history' })
  async getExports(@CurrentTenant() licenseId: string) {
    return this.migrationService.getExports(licenseId);
  }

  @Post('import')
  @ApiOperation({ summary: 'Import server configuration' })
  async importConfig(
    @CurrentTenant() licenseId: string,
    @Body() data: any,
  ) {
    return this.migrationService.importConfig(licenseId, data);
  }
}
