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

    // Summaries and Descriptions for all APIs
    public static final String GET_SALES_KPI_SUMMARY = "Retrieve Sales KPI";
    public static final String GET_SALES_KPI_DESCRIPTION = "Generates a KPI report for sales within the specified date range.";

    public static final String GET_PURCHASE_KPI_SUMMARY = "Retrieve Purchase KPI";
    public static final String GET_PURCHASE_KPI_DESCRIPTION = "Generates a KPI report for purchases within the specified date range.";

    public static final String GET_SUPPLIER_KPI_SUMMARY = "Retrieve Supplier KPI";
    public static final String GET_SUPPLIER_KPI_DESCRIPTION = "Generates a KPI report for suppliers within the specified date range.";

    public static final String GET_TAX_KPI_SUMMARY = "Retrieve Tax KPI";
    public static final String GET_TAX_KPI_DESCRIPTION = "Generates a KPI report for taxes within the specified date range.";

    public static final String GET_PATIENT_PRESCRIPTION_KPI_SUMMARY = "Retrieve Patient Prescription KPI";
    public static final String GET_PATIENT_PRESCRIPTION_KPI_DESCRIPTION = "Generates a KPI report for patient prescriptions within the specified date range.";

    public static final String GET_FINANCIAL_KPI_SUMMARY = "Retrieve Financial KPI";
    public static final String GET_FINANCIAL_KPI_DESCRIPTION = "Generates a KPI report for financials within the specified date range.";

    public static final String GET_INVENTORY_KPI_SUMMARY = "Retrieve Inventory KPI";
    public static final String GET_INVENTORY_KPI_DESCRIPTION = "Generates a KPI report for inventory within the specified date range.";

    public static final String GET_AUDIT_COMPLIANCE_KPI_SUMMARY = "Retrieve Audit Compliance KPI";
    public static final String GET_AUDIT_COMPLIANCE_KPI_DESCRIPTION = "Generates a KPI report for audit compliance within the specified date range.";

    public static final String GET_REVENUE_KPI_SUMMARY = "Retrieve Revenue KPI";
    public static final String GET_REVENUE_KPI_DESCRIPTION = "Generates a KPI report for revenue within the specified date range.";

    // Response Example
    public static final String GET_SALES_KPI_EXAMPLE = """
       {
                   "status": "Success",
                   "meta": {
                       "code": 200,
                       "details": "Data retrieved.",
                       "timestamp": "2025-01-28T22:28:38.45759"
                   },
                   "data": {
                       "total_sales_amount": 114873.0,
                       "total_quantity_sold": 634,
                       "top_product": "Creatine",
                       "average_order_value": 4594.92,
                       "total_orders": 25
                   }
               }
    """;

    public static final String GET_PURCHASE_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved.",
                        "timestamp": "2025-01-28T22:29:38.6820321"
                    },
                    "data": {
                        "total_purchase_order": 7,
                        "total_received_quantity": 1289,
                        "top_supplier_by_orders": "MediSupply Co.",
                        "average_purchase_value": 3363.9439999999995,
                        "total_suppliers": 1
                    }
                }
    """;

    public static final String GET_SUPPLIER_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved.",
                        "timestamp": "2025-01-28T22:29:57.8423777"
                    },
                    "data": {
                        "total_suppliers": 1,
                        "top_supplier_by_orders": "MediSupply Co.",
                        "on_time_delivery_rate": "0.00%",
                        "total_returns": 3,
                        "average_delivery_time": "67.38 hours"
                    }
                }
    """;

    public static final String GET_TAX_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved.",
                        "timestamp": "2025-01-28T22:30:15.8722037"
                    },
                    "data": {
                        "total_taxes_collected": 20677.140,
                        "gst_collected": 20677.140,
                        "total_sales_with_tax": 135550.140
                    }
                }
    """;

    public static final String GET_PATIENT_PRESCRIPTION_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved.",
                        "timestamp": "2025-01-28T22:30:31.0003847"
                    },
                    "data": {
                        "total_patients": 0,
                        "total_prescriptions": 8,
                        "top_prescribed_product": "Creatine",
                        "average_prescription_value": 2400.53,
                        "total_doctors": 0
                    }
                }
    """;

    public static final String GET_FINANCIAL_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved.",
                        "timestamp": "2025-01-28T22:30:55.024044"
                    },
                    "data": {
                        "total_revenue": 114873.0,
                        "total_tax_collected": 20677.140,
                        "total_payments_received": 114873.0,
                        "profit_margin": 20.0,
                        "total_orders": 49
                    }
                }
    """;

    public static final String GET_INVENTORY_KPI_EXAMPLE = """
       {
                   "status": "Success",
                   "meta": {
                       "code": 200,
                       "details": "Data retrieved.",
                       "timestamp": "2025-01-28T22:31:18.6571368"
                   },
                   "data": {
                       "total_stock_value": 20250.00,
                       "total_quantity_in_stock": 135,
                       "low_stock_alerts": 0,
                       "total_products": 10,
                       "average_stock_value_per_product": 2025.00
                   }
               }
    """;

    public static final String GET_AUDIT_COMPLIANCE_KPI_EXAMPLE = """
       {
                   "status": "Success",
                   "meta": {
                       "code": 200,
                       "details": "Data retrieved.",
                       "timestamp": "2025-01-28T22:31:38.0993912"
                   },
                   "data": {
                       "total_inventory_discrepancies": 2,
                       "fulfilled_purchase_orders": 4,
                       "total_purchase_order_compliance": 57.14285714285714,
                       "total_prescription_compliance": 25.0
                   }
               }
    """;

    public static final String GET_REVENUE_KPI_EXAMPLE = """
        {
                    "status": "Success",
                    "meta": {
                        "code": 200,
                        "details": "Data retrieved successfully.",
                        "timestamp": "2025-01-28T22:32:04.1603609"
                    },
                    "data": {
                        "total_taxes_collected": 20677.140,
                        "gst_collected": 20677.140,
                        "total_sales_with_tax": 135550.140,
                        "total_sales_amount": 114873.0,
                        "total_items_sold": 49,
                        "average_sales_amount_per_item": 2344.3
                    }
                }
    """;

    // Internal Server Error Response
    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 {}

    // Modular Annotation for KPI APIs
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_SALES_KPI_SUMMARY,
            description = GET_SALES_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_SALES_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetSalesKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_FINANCIAL_KPI_SUMMARY,
            description = GET_FINANCIAL_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_FINANCIAL_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetFinancialKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_AUDIT_COMPLIANCE_KPI_SUMMARY,
            description = GET_AUDIT_COMPLIANCE_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_AUDIT_COMPLIANCE_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAuditComplianceKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_INVENTORY_KPI_SUMMARY,
            description = GET_INVENTORY_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_INVENTORY_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetInventoryKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_PATIENT_PRESCRIPTION_KPI_SUMMARY,
            description = GET_PATIENT_PRESCRIPTION_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_PATIENT_PRESCRIPTION_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetPatientPrescriptionKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_PURCHASE_KPI_SUMMARY,
            description = GET_PURCHASE_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_PURCHASE_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetPurchaseKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_REVENUE_KPI_SUMMARY,
            description = GET_REVENUE_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_REVENUE_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetRevenueKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_SUPPLIER_KPI_SUMMARY,
            description = GET_SUPPLIER_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_SUPPLIER_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetSupplierKPIOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary =GET_TAX_KPI_SUMMARY,
            description = GET_TAX_KPI_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "KPI data retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_TAX_KPI_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetTaxKPIOperation {}

}
