import { Controller, Get, Post, Body, Patch, Param, Delete, DefaultValuePipe, ParseIntPipe, Query } from '@nestjs/common';
import { QuotesService } from './quotes.service';
import { CreateQuoteDto } from './dto/create-quote.dto';
import { UpdateQuoteDto } from './dto/update-quote.dto';

@Controller('quotes')
export class QuotesController {
	constructor(private readonly quotesService: QuotesService) {}

	@Post()
	create(@Body() createQuoteDto: CreateQuoteDto) {
		return this.quotesService.create(createQuoteDto);
	}

	@Post('email')
	emailQuote(@Body('key') key: string, @Body('email') email: string, @Body('subject') subject: string, @Body('message') message: string, @Body('htmlMessage') htmlMessage: string) {
		return this.quotesService.emailQuote(key, email, subject, message, htmlMessage);
	}

	@Get()
	findAll(@Query('page', new DefaultValuePipe(1), ParseIntPipe) page: number, @Query('limit', new DefaultValuePipe(10), ParseIntPipe) limit: number, @Query('sortBy') sortBy: string, @Query('sortOrder') sortOrder: string, @Query('search') search: string, @Query('status') status: string | undefined) {
		return this.quotesService.findAll((page - 1) * limit, limit, sortBy, sortOrder, search, status);
	}

	@Get('regen/:id')
	regen(@Param('id') id: string) {
		return this.quotesService.regenQuoteKey(+id);
	}

	@Get(':key')
	findOne(@Param('key') key: string) {
		return this.quotesService.findOne(key);
	}

	@Get(':key/proof')
	generateProof(@Param('key') key: string) {
		return this.quotesService.generateProof(key);
	}

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateQuoteDto: UpdateQuoteDto) {
		return this.quotesService.update(+id, updateQuoteDto);
	}

	@Patch(':key/approve')
	approve(@Param('key') key: string) {
		return this.quotesService.approve(key);
	}

	@Patch(':key/reject')
	async reject(@Param('key') key: string, @Body('shippingNotes') shippingNotes: string) {
		return this.quotesService.reject(key, shippingNotes);
	}

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