import { Controller, Get, Post, Body, Patch, Param, Delete, ParseIntPipe, Query, DefaultValuePipe, ParseArrayPipe } from '@nestjs/common';
import { InksService } from './inks.service';
import { CreateInkDto } from './dto/create-ink.dto';
import { UpdateInkDto } from './dto/update-ink.dto';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { Ink } from './entities/ink.entity';

@Controller('inks')
@ApiTags('inks')
export class InksController {
	constructor(private readonly inksService: InksService) {}

	@Post()
	create(@Body() createInkDto: CreateInkDto) {
		return this.inksService.create(createInkDto);
	}

	@Get()
    @ApiOkResponse({ type: Ink, isArray: true })
    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.inksService.findAll((page - 1) * limit, limit, sortBy, sortOrder, search);
    }

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

	@Patch(':id')
	update(@Param('id') id: string, @Body() updateInkDto: UpdateInkDto) {
		return this.inksService.update(+id, updateInkDto);
	}

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

    @Post('/libraries/:library')
	importLibrary(@Param('library') library: string) {
		return this.inksService.importLibrary(library);
	}

    @Delete('/libraries/:library')
	removeLibrary(@Param('library') library: string) {
		return this.inksService.removeLibrary(library);
	}
}
