import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../auth/auth.guard.js';
import { CurrentUser } from '../auth/current-user.decorator.js';
import { ProjectBootstrapService } from './project-bootstrap.service.js';

@Controller('api/workspaces')
@UseGuards(AuthGuard)
export class WorkspaceController {
  constructor(private readonly bootstrap: ProjectBootstrapService) {}

  @Post()
  async create(
    @CurrentUser() user: { id: string },
    @Body()
    body: {
      name: string;
      description?: string;
      teamId?: string;
      repoUrl?: string;
    },
  ) {
    return this.bootstrap.bootstrap({
      name: body.name,
      description: body.description,
      userId: user.id,
      teamId: body.teamId,
      repoUrl: body.repoUrl,
    });
  }
}
