import { Body, Controller, Get, Post, Query } from '@nestjs/common';
import { z } from 'zod';
import { SamudayService } from './samuday.service';
import { ZodValidationPipe } from '../../common/pipes/zod-validation.pipe';
import { RequiresCaptain } from '../../common/decorators/auth.decorators';

const createSamudaySchema = z.object({
  name: z.string().min(2).max(150).trim(),
});

@Controller('samuday')
export class SamudayController {
  constructor(private readonly samuday: SamudayService) {}

  @Get()
  list(@Query('q') q?: string) {
    return this.samuday.list(q);
  }

  @Post()
  @RequiresCaptain()
  create(@Body(new ZodValidationPipe(createSamudaySchema)) input: { name: string }) {
    return this.samuday.create(input.name);
  }
}
