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 SalesSwagger {

    // Summaries and Descriptions
    public static final String GET_SALES_REPORT_SUMMARY = "Retrieve Sales Report";
    public static final String GET_SALES_REPORT_DESCRIPTION = "Generates a sales report based on the provided sales request and report type.";

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

    public static final String GET_SALES_REPORT_RESPONSE_EXAMPLE = """
       {
                     "status": "Success",
                     "meta": {
                         "code": 200,
                         "details": "Data retrieved.",
                         "timestamp": "2025-01-28T20:25:28.2005028"
                     },
                     "data": {
                         "module": "sales",
                         "reportType": "monthly",
                         "startDate": "2025-01-01",
                         "endDate": "2025-12-31",
                         "reportData": [
                             {
                                 "product_id": 17,
                                 "product_name": "Creatine",
                                 "category_id": 31,
                                 "category_name": "Tablet",
                                 "brand_id": 55,
                                 "brand_name": "ON ",
                                 "quantity": 129,
                                 "total_price": 22833.0,
                                 "unit_price": 150.0
                             }
                         ],
                         "column": {
                             "product_id": "PRODUCT ID",
                             "product_name": "PRODUCT NAME",
                             "category_id": "CATEGORY ID",
                             "category_name": "CATEGORY NAME",
                             "brand_id": "BRAND ID",
                             "brand_name": "BRAND NAME",
                             "quantity": "QUANTITY",
                             "total_price": "TOTAL PRICE",
                             "unit_price": "UNIT PRICE"
                         },
                         "pagination": {
                             "currentPage": 1,
                             "totalPages": 5,
                             "pageSize": 10,
                             "totalRecords": 3
                         },
                         "summary": {
                             "totalRevenue": 29264.0,
                             "totalItemsSold": 154,
                             "topSellingBrand": "Creatine"
                         }
                     }
                 }
    """;

    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 Sales Report API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_SALES_REPORT_SUMMARY,
            description = GET_SALES_REPORT_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.reports.requestmodel.SalesRequest.class),
                            examples = @ExampleObject(value = GET_SALES_REPORT_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Sales report generated successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_SALES_REPORT_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetSalesReportOperation {}
}
