import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Request } from '@nestjs/common';
import { EnquiriesService } from './enquiries.service';
import { CreateEnquiryDto } from './dto/create-enquiry.dto';
import { UpdateEnquiryDto } from './dto/update-enquiry.dto';
import { AuthGuard } from '@nestjs/passport';

@Controller('enquiries')
@UseGuards(AuthGuard('jwt'))
export class EnquiriesController {
  constructor(private readonly enquiriesService: EnquiriesService) { }

  @Post()
  create(@Request() req, @Body() createEnquiryDto: CreateEnquiryDto) {
    if (!createEnquiryDto.userId) {
      createEnquiryDto.userId = req.user.id;
    }
    return this.enquiriesService.create(createEnquiryDto);
  }

  @Get()
  findAll(@Request() req) {
    return this.enquiriesService.findAll(req.user);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.enquiriesService.findOne(id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateEnquiryDto: UpdateEnquiryDto) {
    return this.enquiriesService.update(id, updateEnquiryDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.enquiriesService.remove(id);
  }
}
