import { Controller, Get, Post, Patch, Param, Query, Body } from '@nestjs/common';
import { BlocksService } from './blocks.service';

@Controller('blocks')
export class BlocksController {
  constructor(private blocks: BlocksService) {}

  @Get()
  findAll() {
    return this.blocks.findAll();
  }

  @Get('by-path')
  findByPath(@Query('path') path: string) {
    return this.blocks.findByPath(path);
  }

  @Patch('by-path')
  update(
    @Query('path') path: string,
    @Body() body: { version?: string; isInPreview?: boolean; changelog?: object[] },
  ) {
    return this.blocks.update(path, body);
  }

  @Post('snapshots')
  createSnapshot(
    @Query('path') path: string,
    @Body() body: { version: string; changelog: object[]; html: string; css: string },
  ) {
    return this.blocks.createSnapshot(path, body);
  }

  @Get('snapshots')
  listSnapshots(@Query('path') path: string) {
    return this.blocks.listSnapshots(path);
  }

  @Get('snapshots/:id')
  getSnapshot(@Param('id') id: string) {
    return this.blocks.getSnapshot(id);
  }
}
