import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
import { GovernanceDictionaryDto, ImportGovernanceDictionariesDto, RemoveGovernanceDictionaryDto } from './dto/governance-dictionary.dto';
import { GovernanceDictionaryKind, GovernanceService } from './governance.service';

@Controller('governance')
export class GovernanceController {
  constructor(private readonly governanceService: GovernanceService) {}

  @Get('dictionaries')
  list(@Query('kind') kind: GovernanceDictionaryKind) {
    return this.governanceService.list(kind);
  }

  @Post('dictionaries')
  create(@Body() dto: GovernanceDictionaryDto) {
    return this.governanceService.create(dto);
  }

  @Patch('dictionaries/:kind/:id')
  update(
    @Param('kind') kind: GovernanceDictionaryKind,
    @Param('id') id: string,
    @Body() dto: GovernanceDictionaryDto,
  ) {
    return this.governanceService.update({ ...dto, kind, id });
  }

  @Delete('dictionaries/:kind/:id')
  remove(
    @Param('kind') kind: GovernanceDictionaryKind,
    @Param('id') id: string,
    @Body() dto: RemoveGovernanceDictionaryDto,
  ) {
    return this.governanceService.remove({ actorId: dto.actorId, permissions: dto.permissions, kind, id });
  }

  @Get('export')
  exportAll() {
    return this.governanceService.exportAll();
  }

  @Post('import')
  importAll(@Body() dto: ImportGovernanceDictionariesDto) {
    return this.governanceService.importAll(dto.actorId, dto.items, dto.permissions);
  }
}
