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

    // Summaries and Descriptions
    public static final String CREATE_SALES_SUMMARY = "Create a new sale";
    public static final String CREATE_SALES_DESCRIPTION = "Create a new sale, including sales items and payment information.";

    public static final String GET_SALES_BY_ID_SUMMARY = "Retrieve sales by ID";
    public static final String GET_SALES_BY_ID_DESCRIPTION = "Retrieve a specific sale by its unique ID, including sales items and payment details.";

    public static final String GET_ALL_SALES_SUMMARY = "Retrieve all sales with pagination";
    public static final String GET_ALL_SALES_DESCRIPTION = "Retrieve a paginated list of all sales, including sales items and payment details.";

    public static final String EXPORT_SALES_BY_ID_SUMMARY = "Export sales by ID";
    public static final String EXPORT_SALES_BY_ID_DESCRIPTION = "Export details of a specific sale by its unique ID.";

    //Example Requests
    public static final String CREATE_SALES_REQUEST_EXAMPLE = """
            {
                "prescription_id": "8984612321",
                "encounter_id": "65321546546",
                "patient_id": "8984612321",
                "patient_name": "kumar",
                "customer_name": "kumar",
                "customer_mobile": "9874563210",
                "customer_email": "kumar@mail.com",
                "customer_dob": "01-01-2024",
                "customer_address": "some street name, some area, some city, some state, some country, 97865",
                "payment_status": "completed",
                "sales_items": [
                    {
                        "product_id": 12,
                        "quantity": 50,
                        "type":"product"
                    }
                ],
                "amount_paid": 1.00,
                "date": "2024-08-31T10:00:00",
                "payment_method": "cash"
            }
        """;

    //Example Response
    public static final String CREATE_SALES_EXAMPLE = """
        {
            "status": "success",
            "meta": {
                "code": 201,
                "details": "Sales created successfully",
                "timestamp": "2025-01-28T09:17:44.3719169"
            },
            "data": {
                "id": 81,
                "date": "2025-01-27T18:30:00",
                "prescription_id": "31",
                "encounter_id": "2ab4e6ef-cf8f-4ee5-be47-a9d1c48be2d5-1",
                "patient_id": "70ec91a2-f743-416a-854e-69ef14302bb4",
                "patient_name": "Mr. Vigneshkumar Kumar K",
                "customer_name": "Vino",
                "customer_mobile": "9943474260",
                "customer_email": "test@gmail.com",
                "customer_dob": "2025-01-27T18:30:00.000Z",
                "customer_address": "tests",
                "total_amount": 3363.0,
                "payment_status": "paid",
                "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                "tenant": "Arise_Tenant",
                "sales_items": [
                    {
                        "id": 113,
                        "product_id": 17,
                        "quantity": 3,
                        "unit_price": 150.0,
                        "total_price": 531.0,
                        "batch_code": "123",
                        "type": "product",
                        "tax_id": 13,
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-28T09:17:43.7495425",
                        "updated_at": "2025-01-28T09:17:43.7495425",
                        "deleted_at": null
                    }
                ],
                "payments": null,
                "created_at": "2025-01-28T09:17:42.7124213",
                "updated_at": "2025-01-28T09:17:42.7124213",
                "deleted_at": null
            }
        }
        """;

    public static final String GET_SALES_BY_ID_EXAMPLE = """
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Sales retrieved successfully",
                    "timestamp": "2025-01-28T09:28:58.0655913"
                },
                "data": {
                    "id": 58,
                    "prescription_id": "35",
                    "encounter_id": "2ab4e6ef-cf8f-4ee5-be47-a9d1c48be2d5-2",
                    "patient_id": "113f899e-2997-428b-bd43-35669301775b",
                    "patient_name": "Mr. Vigneshkumar Kumar K",
                    "customer_name": "Mr. Vigneshkumar Kumar K",
                    "customer_mobile": "8248095837",
                    "customer_email": "vignesh@gmail.com",
                    "customer_dob": "2025-01-20T18: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",
                    "total_amount": 354.0,
                    "payment_status": "paid",
                    "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                    "created_at": "2025-01-21T11:56:52.905239",
                    "sales_items": [
                        {
                            "id": 72,
                            "type": "product",
                            "product_id": 17,
                            "product_name": "Creatine",
                            "brand_id": 55,
                            "brand_name": "ON ",
                            "category_id": 31,
                            "category_name": "Tablet",
                            "unit_price": 150.0,
                            "tax_id": 13,
                            "tax_rate": 18.0,
                            "stock_quantity": 125,
                            "quantity": 2,
                            "batch_code": "123",
                            "total_price": 354.0,
                            "tax_amount": 204.00,
                            "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                            "created_at": "2025-01-21T11:56:53.233748"
                        }
                    ],
                    "payments": {
                        "amount_paid": 354.0,
                        "payment_method": "debit_card",
                        "date": "2025-01-20T18:30:00"
                    },
                    "columns": {
                        "id": "ID",
                        "product_id": "PRODUCT ID",
                        "product_name": "PRODUCT NAME",
                        "brand_id": "BRAND ID",
                        "brand_name": "BRAND NAME",
                        "category_id": "CATEGORY ID",
                        "category_name": "CATEGORY NAME",
                        "quantity": "QUANTITY",
                        "batch_code": "BATCH CODE",
                        "unit_price": "UNIT PRICE",
                        "total_price": "TOTAL PRICE",
                        "tax_id": "TAX ID",
                        "tax_amount": "TAX AMOUNT",
                        "tax_rate": "TAX RATE",
                        "created_by": "CREATED BY",
                        "created_at": "CREATED AT"
                    }
                }
            }
        """;

    public static final String GET_ALL_SALES_EXAMPLE="""
        {
                 "status": "success",
                 "meta": {
                     "code": 200,
                     "details": "Sales retrieved successfully",
                     "timestamp": "2025-01-28T09:17:48.5291577"
                 },
                 "data": {
                     "pagination": {
                         "current_page": 1,
                         "per_page": 10,
                         "total": 25,
                         "last_page": 3,
                         "next_page_url": "/api/sales?page=1&size=10",
                         "prev_page_url": null
                     },
                     "items": [
                         {
                             "id": 38,
                             "prescription_id": null,
                             "encounter_id": "ff525c2a-a80c-4f09-8939-f312a73908a2",
                             "patient_id": "113f899e-2997-428b-bd43-35669301775b",
                             "patient_name": "",
                             "customer_name": "",
                             "customer_mobile": "",
                             "customer_email": "",
                             "customer_dob": "",
                             "customer_address": "",
                             "total_amount": 413.0,
                             "payment_status": "paid",
                             "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                             "created_at": "2025-01-12T16:06:17.296751",
                             "sales_items": [
                                 {
                                     "id": 44,
                                     "type": "service",
                                     "product_id": 20,
                                     "product_name": null,
                                     "tax_id": 13,
                                     "tax_rate": 18.0,
                                     "unit_price": 350.0,
                                     "measurement": "hourly",
                                     "quantity": 1,
                                     "batch_code": null,
                                     "total_price": 413.0,
                                     "tax_amount": 63.00,
                                     "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                                     "created_at": "2025-01-12T16:06:17.296751"
                                 }
                             ],
                             "payments": {
                                 "amount_paid": 413.0,
                                 "payment_method": "debit_card",
                                 "date": "2025-01-11T18:30:00"
                             }
                         }
                     ],
                     "columns": {
                         "id": "ID",
                         "encounter_id": "ENCOUNTER ID",
                         "patient_id": "PATIENT ID",
                         "patient_name": "PATIENT NAME",
                         "customer_name": "CUSTOMER NAME",
                         "customer_mobile": "CUSTOMER MOBILE",
                         "total_amount": "TOTAL AMOUNT",
                         "payment_status": "PAYMENT STATUS",
                         "created_by": "CREATED BY",
                         "created_at": "CREATED AT"
                     }
                 }
             }
    """;

    public static final String EXPORT_SALES_BY_ID_EXAMPLE="""
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Sales retrieved successfully",
                    "timestamp": "2025-01-28T09:30:25.685057"
                },
                "data": {
                    "id": 58,
                    "prescription_id": "35",
                    "encounter_id": "2ab4e6ef-cf8f-4ee5-be47-a9d1c48be2d5-2",
                    "patient_id": "113f899e-2997-428b-bd43-35669301775b",
                    "patient_name": "Mr. Vigneshkumar Kumar K",
                    "customer_name": "Mr. Vigneshkumar Kumar K",
                    "customer_mobile": "8248095837",
                    "customer_email": "vignesh@gmail.com",
                    "customer_dob": "2025-01-20T18: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",
                    "total_amount": 354.0,
                    "payment_status": "paid",
                    "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                    "created_at": "2025-01-21T11:56:52.905239",
                    "total_tax_amount": 54.0,
                    "sales_items": [
                        {
                            "id": 72,
                            "type": "product",
                            "product_id": 17,
                            "product_name": "Creatine",
                            "brand_id": 55,
                            "brand_name": "ON ",
                            "category_id": 31,
                            "category_name": "Tablet",
                            "unit_price": 150.0,
                            "tax_id": 13,
                            "tax_rate": 18.0,
                            "stock_quantity": 125,
                            "quantity": 2,
                            "batch_code": "123",
                            "total_price": 354.0,
                            "tax_amount": 54.00,
                            "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                            "created_at": "2025-01-21T11:56:53.233748"
                        }
                    ],
                    "payments": {
                        "amount_paid": 354.0,
                        "payment_method": "debit_card",
                        "date": "2025-01-20T18:30:00"
                    },
                    "organization": {
                        "id": "4b24f4f6-b417-4610-949d-8af433332b01",
                        "organization_name": "Arise-Coimbatore",
                        "organization_type": "Healthcare Provider",
                        "organization_code": "prov",
                        "address": "Coimbatore",
                        "city": "Coimbatore",
                        "district": "Coimbatore",
                        "state": "Tamilnadu",
                        "country": "India",
                        "postal_code": "600001",
                        "organization_phone": "8734859330",
                        "organization_email": "vignesh@gmail.com",
                        "orgId": "681648ff-cec7-4d23-8ff4-2a74bd14db25",
                        "parent_id": "ff3cca54-b84e-4f6a-9723-3750b234e61b",
                        "parent_name": "Arise",
                        "tenant_name": "Arise_Tenant"
                    },
                    "columns": {
                        "id": "ID",
                        "product_id": "PRODUCT ID",
                        "product_name": "PRODUCT NAME",
                        "brand_id": "BRAND ID",
                        "brand_name": "BRAND NAME",
                        "category_id": "CATEGORY ID",
                        "category_name": "CATEGORY NAME",
                        "quantity": "QUANTITY",
                        "batch_code": "BATCH CODE",
                        "unit_price": "UNIT PRICE",
                        "total_price": "TOTAL PRICE",
                        "tax_id": "TAX ID",
                        "tax_amount": "TAX AMOUNT",
                        "tax_rate": "TAX RATE",
                        "created_by": "CREATED BY",
                        "created_at": "CREATED AT"
                    }
                }
            }
    """;

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

    // Global Error Response
    @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 Annotations for Each API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = CREATE_SALES_SUMMARY,
            description = CREATE_SALES_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.sales.requestmodel.SalesRequest.class),
                            examples = @ExampleObject(value = CREATE_SALES_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "201",
                            description = "Sales created successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = CREATE_SALES_EXAMPLE)
                            )
                    )
            }
    )
    public @interface CreateSalesOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_SALES_BY_ID_SUMMARY,
            description = GET_SALES_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Sales retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_SALES_BY_ID_EXAMPLE)
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Sales not found",
                            content = @Content(mediaType = "application/json")
                    )
            }
    )
    public @interface GetSalesByIdOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_SALES_SUMMARY,
            description = GET_ALL_SALES_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Sales retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_ALL_SALES_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllSalesOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = EXPORT_SALES_BY_ID_SUMMARY,
            description = EXPORT_SALES_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Sales exported successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = EXPORT_SALES_BY_ID_EXAMPLE)
                            )
                    )
            }
    )
    public @interface ExportSalesByIdOperation {}
}