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

    // Summaries and Descriptions
    public static final String GET_PATIENT_PRESCRIPTION_SUMMARY = "Retrieve Patient Prescription Report";
    public static final String GET_PATIENT_PRESCRIPTION_DESCRIPTION = "Generates a report based on patient prescriptions, filtered by the specified report type.";

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

    public static final String GET_PATIENT_PRESCRIPTION_RESPONSE_EXAMPLE = """
       {
                     "status": "Success",
                     "meta": {
                         "code": 200,
                         "details": "Data retrieved.",
                         "timestamp": "2025-01-28T20:20:06.0692687"
                     },
                     "data": {
                         "module": "sales",
                         "reportType": "patientPrescriptionHistory",
                         "startDate": "2025-01-01",
                         "endDate": "2025-12-31",
                         "reportData": [
                             {
                                 "prescription_id": 30,
                                 "patient_id": "113f899e-2997-428b-bd43-35669301775b",
                                 "doctor_id": "3ea5b334-050d-47c2-8647-24380557243d",
                                 "encounter_id": "ff525c2a-a80c-4f09-8939-f312a73908a2",
                                 "patient_name": "-",
                                 "class_name": "-",
                                 "prescription_date": "2025-01-12T11:28:20.687+00:00",
                                 "prescriptions_items": [
                                     {
                                         "product_id": 20,
                                         "product_name": null,
                                         "category_id": null,
                                         "category_name": null,
                                         "brand_id": null,
                                         "brand_name": null,
                                         "quantity_prescribed": 2
                                     }
                                 ]
                             }
                         ],
                         "column": {
                             "prescription_id": "PRESCRIPTION ID",
                             "patient_id": "PATIENT ID",
                             "patient_name": "PATIENT NAME",
                             "doctor_id": "DOCTOR ID",
                             "doctor_name": "DOCTOR ID",
                             "encounter_id": "ENCOUNTER ID",
                             "class_name": "CLASS NAME",
                             "prescription_date": "PRESCRIPTION DATE",
                             "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_prescribed": "QUANTITY PRESCRIBED"
                         },
                         "pagination": {
                             "currentPage": 1,
                             "totalPages": 1,
                             "pageSize": 10,
                             "totalRecords": 8
                         },
                         "summary": {
                             "totalPatients": 0,
                             "totalPrescriptionsIssued": 8,
                             "topPrescribedProduct": "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 Patient Prescription API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_PATIENT_PRESCRIPTION_SUMMARY,
            description = GET_PATIENT_PRESCRIPTION_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_PATIENT_PRESCRIPTION_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Patient Prescription report generated successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_PATIENT_PRESCRIPTION_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetPatientPrescriptionReportOperation {}
}
