/**
 * OwnSets Controller - General setup API
 */
import { Controller, Get, Put, Body, Param, Query, UseGuards } from '@nestjs/common';
import { OwnsetsService } from './ownsets.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@Controller('ownsets')
@UseGuards(JwtAuthGuard)
export class OwnsetsController {
  constructor(private ownsetsService: OwnsetsService) {}

  @Get()
  findByType(@Query('type') type: string) {
    const t = parseInt(type || '404', 10);
    return this.ownsetsService.findByType(t);
  }

  @Get(':type/:id')
  findOne(@Param('type') type: string, @Param('id') id: string) {
    return this.ownsetsService.findOne(parseInt(type, 10), parseInt(id, 10));
  }

  @Put(':type/:id')
  upsert(
    @Param('type') type: string,
    @Param('id') id: string,
    @Body() body: Record<string, unknown>,
  ) {
    return this.ownsetsService.upsert(parseInt(type, 10), parseInt(id, 10), body);
  }
}
