import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Query,
} from "@nestjs/common";
import { ReaderService } from "./reader.service";
import { CreateReaderDto } from "./dto/create-reader.dto";
import { UpdateReaderDto } from "./dto/update-reader.dto";
// import { UpdateReaderDto } from './dto/update-reader.dto';
import { JwtAuthGuard } from "src/auth/guards/jwt-auth.guard";
import { ReaderType } from "@prisma/client";
@Controller("reader")
export class ReaderController {
  constructor(private readonly readerService: ReaderService) { }

  @Post()
  create(@Body() createReaderDto: CreateReaderDto) {
    return this.readerService.create(createReaderDto);
  }
  // @Post("/assign-to-warehouse")
  // assignToWarehouse(@Body() body: any) {
  //   let { reader_id, warehouse_id, type } = body;
  //   if (type == "INSIDE") {
  //     type = ReaderType.INSIDE;
  //   } else if (type == "OUTSIDE") {
  //     type = ReaderType.OUTSIDE;
  //   }
  //   return this.readerService.assignToWarehouse(reader_id, warehouse_id, type);
  // }

  @Get()
  findAll(
    @Query("page") page: number,
    @Query("perPage") perPage: number,
    @Query("search") search: string,
    @Query("type") type: string
  ) {
    return this.readerService.findAll(page, perPage, search, type);
  }

  @Get("unused")
  findInReaders(@Query("readerIdToInclude") readerIdToInclude?: string) {
    return this.readerService.findInReaders(readerIdToInclude);
  }

  @Get(":id")
  findOne(@Param("id") id: string) {
    return this.readerService.findOne(id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateReaderDto: UpdateReaderDto) {
    return this.readerService.update(id, updateReaderDto);
  }

  @Delete(":id")
  remove(@Param("id") id: string) {
    return this.readerService.remove(id);
  }
}
