import { Body, Controller, Delete, Get, Post, Query } from "@nestjs/common";
import ResponseDto from "../../dto/response.dto";
import { DocumentCreateDto, DocumentFilterDto, DocumentMovementListDto } from "../../dto/document.dto";
import DocumentProvider from "./document.provider";
import { ApiQuery } from "@nestjs/swagger";

@Controller("/api/v1/document")
export default class DocumentController {

    constructor(private readonly documentProvider: DocumentProvider){}

    @Post("/create")
    async create(@Body() payload: DocumentCreateDto): Promise<ResponseDto>{
        return await this.documentProvider.create(payload);
    }

    @Get("/getDocumentById")
    async getDocumentById(@Query("id") id: number): Promise<ResponseDto>{    
        return await this.documentProvider.getDocumentById(id);
    }

    @Get("/getDocumentsByNumber")
    async getDocumentsByNumber(@Query("filterFor") filterFor: 'receiptNumber' | 'documentNumber', @Query("filterValue") filterValue: string): Promise<ResponseDto>{
        return await this.documentProvider.getDocumentsByNumber(filterFor, filterValue);
    }

    @Get("/getBaseDataForDocument")
    async getBaseDataForDocument(){
        return await this.documentProvider.getBaseDataForDocument();
    }

    @ApiQuery({name: "idNext", required: false})
    @Post("/list")
    async list(@Body() payload: DocumentFilterDto, @Query("idNext") idNext?: number): Promise<ResponseDto>{
        return await this.documentProvider.list(payload, idNext);
    }

    @ApiQuery({name: "idNext", required: false})
    @Post("/listMovements")
    async listMovements(@Body() payload: DocumentMovementListDto, @Query("idNext") idNext?: number): Promise<ResponseDto>{
        return await this.documentProvider.listMovements(payload, idNext);
    }

    @ApiQuery({name: "idDocument"})
    @Delete("/trashDocument")
    async trashDocument(@Query("idDocument") idDocument: number): Promise<ResponseDto>{
        return await this.documentProvider.trashDocument(idDocument);
    }

    @Get("/getIpoteticalProgressiveNumber")
    async getIpoteticalProgressiveNumber(@Query("documentArea") documentArea: string, @Query("idStore") idStore: number): Promise<ResponseDto>{
        return await this.documentProvider.getIpoteticalProgressiveNumber(documentArea, idStore);
    }   

    @Get("/getIpoteticalDocumentNumber")
    async getIpoteticalDocumentNumber(@Query("documentArea") documentArea: string, @Query("idCounter") idCounter: number): Promise<ResponseDto>{
        return await this.documentProvider.getIpoteticalDocumentNumber(documentArea, idCounter);
    }

    @Get("/getInvoiceOrCreditNoteXML")
    async getInvoiceOrCreditNoteXML(@Query("idDocument") idDocument: number): Promise<ResponseDto>{
        return await this.documentProvider.getInvoiceOrCreditNoteXML(idDocument);
    }

}