package com.nebula.erp.reports.documents;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class SupplierSwagger {

    // Summaries and Descriptions
    public static final String GET_SUPPLIER_REPORT_SUMMARY = "Retrieve Supplier Report";
    public static final String GET_SUPPLIER_REPORT_DESCRIPTION = "Generates a supplier report based on the provided purchase request and report type.";

    // Request and Response Examples
    public static final String GET_SUPPLIER_REPORT_REQUEST_EXAMPLE = """
        {
                    "startDate": "2025-01-01",
                    "endDate": "2025-12-31",
                    "conditions": [],
                    "page": 0,
                    "size": 10
         }
    """;

    public static final String GET_SUPPLIER_REPORT_RESPONSE_EXAMPLE = """
       {
                     "status": "Success",
                     "meta": {
                         "code": 200,
                         "details": "Data retrieved.",
                         "timestamp": "2025-01-28T20:22:05.6067278"
                     },
                     "data": {
                         "module": "supplier",
                         "reportType": "byPerformance",
                         "startDate": "2025-01-01",
                         "endDate": "2025-12-31",
                         "reportData": [
                             {
                                 "supplier_id": "14",
                                 "supplier_name": "MediSupply Co.",
                                 "purchases": [
                                     {
                                         "purchase_id": 71,
                                         "purchase_date": "2025-01-27T18:30:00",
                                         "date_difference": -8,
                                         "grns": [
                                             {
                                                 "grn_item_id": 62,
                                                 "grn_date": "2025-01-19T18:30:00",
                                                 "grn_quantity": 100,
                                                 "grn_total_price": 708.0,
                                                 "product_id": 17,
                                                 "product_name": "Creatine",
                                                 "category_id": 31,
                                                 "category_name": "Tablet",
                                                 "brand_id": 55,
                                                 "brand_name": "ON "
                                             }
                                         ]
                                     }
                                 ]
                             }
                         ],
                         "column": {
                             "supplier_id": "SUPPLIER ID",
                             "supplier_name": "SUPPLIER NAME",
                             "purchase_id": "PURCHASE ID",
                             "purchase_date": "PURCHASE DATE",
                             "date_difference": "DATE DIFFERENCE (DAYS)",
                             "grn_item_id": "GRN ITEM ID",
                             "grn_date": "GRN DATE",
                             "grn_quantity": "GRN QUANTITY",
                             "grn_total_price": "GRN TOTAL PRICE",
                             "product_id": "PRODUCT ID",
                             "product_name": "PRODUCT NAME",
                             "category_id": "CATEGORY ID",
                             "category_name": "CATEGORY NAME",
                             "brand_id": "BRAND ID",
                             "brand_name": "BRAND NAME"
                         },
                         "pagination": {
                             "currentPage": 1,
                             "totalPages": 1,
                             "pageSize": 10,
                             "totalRecords": 1
                         },
                         "summary": {
                             "totalSuppliers": 1,
                             "onTimeDeliveryRate": 100.0
                         }
                     }
                 }
    """;

    public static final String INTERNAL_SERVER_ERROR_RESPONSE = """
        {
            "status": "error",
            "meta": {
                "code": 500,
                "message": "Internal Server Error"
            }
        }
    """;

    // Global Error Response Annotation
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @ApiResponse(
            responseCode = "500",
            description = "Internal Server Error",
            content = @Content(
                    mediaType = "application/json",
                    examples = @ExampleObject(value = INTERNAL_SERVER_ERROR_RESPONSE)
            )
    )
    public @interface GlobalErrorResponse {}

    // Annotation for Supplier Report API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_SUPPLIER_REPORT_SUMMARY,
            description = GET_SUPPLIER_REPORT_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.reports.requestmodel.PurchaseRequest.class),
                            examples = @ExampleObject(value = GET_SUPPLIER_REPORT_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Supplier report generated successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_SUPPLIER_REPORT_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetSupplierReportOperation {}
}
