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

@ApiTags('modules')
@ApiBearerAuth()
@Controller('modules')
export class StoreController {
  constructor(private readonly storeService: StoreService) {}

  @Get('catalog')
  @ApiOperation({ summary: 'Get module marketplace catalog' })
  async getCatalog() {
    return this.storeService.getCatalog();
  }

  @Get('my-modules')
  @ApiOperation({ summary: 'Get purchased and installed modules for current license' })
  async getMyModules(@CurrentTenant() licenseId: string) {
    return this.storeService.getMyModules(licenseId);
  }

  @Post('purchase')
  @ApiOperation({ summary: 'Purchase a module' })
  async purchaseModule(
    @CurrentTenant() licenseId: string,
    @Body('module_id') moduleId: string,
  ) {
    return this.storeService.purchaseModule(licenseId, moduleId);
  }

  @Post('install')
  @ApiOperation({ summary: 'Install a purchased module' })
  async installModule(
    @CurrentTenant() licenseId: string,
    @Body('module_id') moduleId: string,
  ) {
    return this.storeService.installModule(licenseId, moduleId);
  }
}
