import { Controller, Get, Post, Body, Patch, Param, Delete, ParseIntPipe, Query, DefaultValuePipe, ParseArrayPipe } from '@nestjs/common';
import { FeesService } from './fees.service';
import { CreateFeeDto } from './dto/create-fee.dto';
import { UpdateFeeDto } from './dto/update-fee.dto';
import { ApiTags } from '@nestjs/swagger';

@Controller('fees')
@ApiTags('fees')
export class FeesController {
	constructor(private readonly feesService: FeesService) {}

	@Post()
	create(@Body() createFeeDto: CreateFeeDto) {
		return this.feesService.create(createFeeDto);
	}

	@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) {
		return this.feesService.findAll((page - 1) * limit, limit, sortBy, sortOrder, search);
	}

	// get with jobId
	@Get()
	findByJobId(@Query() params: any) {
		// if (!params.jobId) return this.feesService.findAll();
		return this.feesService.findByJobId(parseInt(params.jobId));
	}

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

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateFeeDto: UpdateFeeDto) {
		return this.feesService.update(+id, updateFeeDto);
	}

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