package com.nebula.erp.sales.document;

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

    // Summaries and Descriptions
    public static final String CREATE_PRESCRIPTION_SUMMARY = "Create a new prescription";
    public static final String CREATE_PRESCRIPTION_DESCRIPTION = "Creates a new prescription record including patient ID, doctor ID, and associated prescription items.";

    public static final String GET_PRESCRIPTION_BY_ID_SUMMARY = "Retrieve prescription by ID";
    public static final String GET_PRESCRIPTION_BY_ID_DESCRIPTION = "Fetches the details of a prescription and its items by its unique ID.";

    public static final String GET_ALL_PRESCRIPTIONS_SUMMARY = "Retrieve all prescriptions";
    public static final String GET_ALL_PRESCRIPTIONS_DESCRIPTION = "Retrieves all prescription records with pagination support.";

    //Example Requests
    public static final String CREATE_PRESCRIPTION_REQUEST_EXAMPLE= """
           {
                "patient_id": "28e8f085-991e-494d-81c8-3c969e9d4b60",
                "doctor_id": "5bf365b0-c49d-453c-8400-1c963bec1376",
                "encounter_id": "647888bd-1194-4380-b376-a8075a8a2359",
                "date": "2024-12-14",
                "prescription_items":[
                    {
                        "type": "service",
                        "product_id": 1,
                        "quantity":1
                    },
                    {
                        "type": "product",
                        "product_id":1,
                        "quantity":10
                    },
                    {
                        "type": "product",
                        "product_name":"Crocin",
                        "quantity":10
                    }
                ]
            }
           """;

    // Example Response
    public static final String CREATE_PRESCRIPTION_EXAMPLE = """
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Prescription created successfully",
                    "timestamp": "2024-09-20T14:14:43.6263149"
                },
                "data": {
                    "id": 12345,
                    "patient_id": 98765,
                    "doctor_id": 54321,
                    "encounter_id": 1234,
                    "date": "2024-09-20T09:50:02.656Z",
                    "created_by": "john.doe@example.com",
                    "tenant": "Tenant_A",
                    "created_at": "2024-09-20T09:50:02.656Z",
                    "updated_at": "2024-09-21T10:00:00.000Z",
                    "deleted_at": null,
                    "prescription_items": [
                        {
                            "id": 1,
                            "prescription_id": 12345,
                            "product_id": 55555,
                            "quantity": 2,
                            "created_by": "john.doe@example.com",
                            "tenant": "Tenant_A",
                            "created_at": "2024-09-20T09:50:02.656Z",
                            "updated_at": "2024-09-21T10:00:00.000Z",
                            "deleted_at": null
                        }
                    ]
                }
            }
            """;

    public static final String GET_ALL_PRESCRIPTIONS_EXAMPLE = """
            {
                 "status": "success",
                 "meta": {
                     "code": 200,
                     "details": "Prescriptions retrieved successfully",
                     "timestamp": "2025-01-28T10:37:56.0389674"
                 },
                 "data": {
                     "pagination": {
                         "current_page": 1,
                         "per_page": 10,
                         "total": 8,
                         "last_page": 1,
                         "next_page_url": null,
                         "prev_page_url": null
                     },
                     "items": [
                         {
                             "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": "-",
                             "practitioner_name": "-",
                             "customer_name": "Mr. Vigneshkumar Kumar K",
                             "customer_mobile": "8248095837",
                             "customer_email": "vignesh@gmail.com",
                             "customer_dob": "1998-05-28T18:30:00.000Z",
                             "customer_address": "2/486, THANTHAI PERIYAR NAGAR, POONDI RING ROAD, ANGERIPALAYAM, Chettipalayam, Tiruppur, Tiruppur, Tamil Nadu , Chettipalayam, TIRUPPUR, TAMIL NADU, India - 641603",
                             "date": "2025-01-12T11:28:20.687+00:00",
                             "created_by": "8cd84ff6-acd7-45b7-8760-b63debd87d1f",
                             "tenant": "Arise_Tenant",
                             "created_at": "2025-01-12T16:58:21.379779",
                             "updated_at": "2025-01-12T16:58:21.379779",
                             "prescriptions_items": [
                                 {
                                     "id": 265,
                                     "type": "service",
                                     "product_id": 20,
                                     "fees_type": null,
                                     "tax_id": 13,
                                     "tax_rate": 18.0,
                                     "rate": 350.0,
                                     "measurement": "hourly",
                                     "quantity": 2,
                                     "created_by": "8cd84ff6-acd7-45b7-8760-b63debd87d1f",
                                     "tenant": "Arise_Tenant",
                                     "created_at": "2025-01-12T16:58:21.379779",
                                     "updated_at": "2025-01-12T16:58:21.379779"
                                 }
                             ]
                         }
                     ],
                     "columns": {
                         "id": "ID",
                         "patient_id": "PATIENT ID",
                         "doctor_id": "DOCTOR ID",
                         "encounter_id": "ENCOUNTER ID",
                         "date": "DATE",
                         "created_by": "CREATED BY",
                         "tenant": "TENANT",
                         "created_at": "CREATED AT",
                         "updated_at": "UPDATED AT"
                     }
                 }
             }
            """;

    public static final String GET_PRESCRIPTON_BY_ID_EXAMPLE = """
            {
                 "status": "success",
                 "meta": {
                     "code": 200,
                     "details": "Prescription retrieved successfully",
                     "timestamp": "2025-01-28T10:37:56.0389674"
                 },
                 "data": {
                     "pagination": {
                         "current_page": 1,
                         "per_page": 10,
                         "total": 8,
                         "last_page": 1,
                         "next_page_url": null,
                         "prev_page_url": null
                     },
                     "items": [
                         {
                             "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": "-",
                             "practitioner_name": "-",
                             "customer_name": "Mr. Vigneshkumar Kumar K",
                             "customer_mobile": "8248095837",
                             "customer_email": "vignesh@gmail.com",
                             "customer_dob": "1998-05-28T18:30:00.000Z",
                             "customer_address": "2/486, THANTHAI PERIYAR NAGAR, POONDI RING ROAD, ANGERIPALAYAM, Chettipalayam, Tiruppur, Tiruppur, Tamil Nadu , Chettipalayam, TIRUPPUR, TAMIL NADU, India - 641603",
                             "date": "2025-01-12T11:28:20.687+00:00",
                             "created_by": "8cd84ff6-acd7-45b7-8760-b63debd87d1f",
                             "tenant": "Arise_Tenant",
                             "created_at": "2025-01-12T16:58:21.379779",
                             "updated_at": "2025-01-12T16:58:21.379779",
                             "prescriptions_items": [
                                 {
                                     "id": 265,
                                     "type": "service",
                                     "product_id": 20,
                                     "fees_type": null,
                                     "tax_id": 13,
                                     "tax_rate": 18.0,
                                     "rate": 350.0,
                                     "measurement": "hourly",
                                     "quantity": 2,
                                     "created_by": "8cd84ff6-acd7-45b7-8760-b63debd87d1f",
                                     "tenant": "Arise_Tenant",
                                     "created_at": "2025-01-12T16:58:21.379779",
                                     "updated_at": "2025-01-12T16:58:21.379779"
                                 }
                             ]
                         }
                     ],
                     "columns": {
                         "id": "ID",
                         "patient_id": "PATIENT ID",
                         "doctor_id": "DOCTOR ID",
                         "encounter_id": "ENCOUNTER ID",
                         "date": "DATE",
                         "created_by": "CREATED BY",
                         "tenant": "TENANT",
                         "created_at": "CREATED AT",
                         "updated_at": "UPDATED AT"
                     }
                 }
             }
            """;

    public static final String INTERNAL_SERVER_ERROR_EXAMPLE = """
        {
            "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_EXAMPLE)
            )
    )
    public @interface GlobalErrorResponse {}

    // Modular Annotations
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = CREATE_PRESCRIPTION_SUMMARY,
            description = CREATE_PRESCRIPTION_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.sales.requestmodel.PrescriptionsRequest.class),
                            examples = @ExampleObject(value = CREATE_PRESCRIPTION_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "201",
                            description = "Prescription created successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = CREATE_PRESCRIPTION_EXAMPLE)
                            )
                    )
            }
    )
    public @interface CreatePrescriptionOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_PRESCRIPTION_BY_ID_SUMMARY,
            description = GET_PRESCRIPTION_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Prescription retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_PRESCRIPTON_BY_ID_EXAMPLE)
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Prescription not found",
                            content = @Content(mediaType = "application/json")
                    )
            }
    )
    public @interface GetPrescriptionByIdOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_PRESCRIPTIONS_SUMMARY,
            description = GET_ALL_PRESCRIPTIONS_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Prescriptions retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_ALL_PRESCRIPTIONS_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllPrescriptionsOperation {}
}