import { Controller, Get, HttpException, HttpStatus } from '@nestjs/common';
import { ModulesService } from './modules.service';
import { Public } from '../auth/public.decorator';
import { ApiBearerAuth, ApiTags, ApiOperation } from '@nestjs/swagger';

@ApiTags('modules')
@ApiBearerAuth('access-token')
@Controller('modules')
export class ModulesController {
  constructor(private readonly modulesService: ModulesService) {}

  @Public() //
  @Get('list_modules')
  @ApiOperation({ summary: 'List all modules' })
  async getModules() {
    try {
      const modules = await this.modulesService.findAll();
      return { success: true, data: modules };
    } catch (error) {
      throw new HttpException(
        { success: false, message: error.message },
        HttpStatus.INTERNAL_SERVER_ERROR,
      );
    }
  }
}
