package com.nebula.erp.inventory.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 InventorySwagger {

    // Summaries and Descriptions
    public static final String GET_ALL_INVENTORIES_SUMMARY = "Retrieve all inventories";
    public static final String GET_ALL_INVENTORIES_DESCRIPTION = "Fetches a paginated list of all inventories.";

    public static final String GET_BATCH_BY_ID_SUMMARY = "Retrieve inventory batch by ID";
    public static final String GET_BATCH_BY_ID_DESCRIPTION = "Fetches details of a specific inventory batch by its unique ID.";

    // Request and Response Examples
    public static final String GET_ALL_INVENTORIES_RESPONSE_EXAMPLE = """
       {
                     "status": "success",
                     "meta": {
                         "code": 200,
                         "details": "Inventories listed successfully",
                         "timestamp": "2025-01-28T16:22:07.9887705"
                     },
                     "data": {
                         "pagination": {
                             "current_page": 1,
                             "per_page": 10,
                             "total": 1,
                             "last_page": 1,
                             "next_page_url": null,
                             "prev_page_url": null
                         },
                         "items": [
                             {
                                 "product_id": 17,
                                 "total_quantity": 135,
                                 "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
                             }
                         ],
                         "columns": {
                             "product_id": "PRODUCT ID",
                             "product_name": "PRODUCT NAME",
                             "brand_id": "BRAND ID",
                             "brand_name": "BRAND NAME",
                             "category_id": "CATEGORY ID",
                             "category_name": "CATEGORY NAME",
                             "total_quantity": "TOTAL QUANTITY"
                         }
                     }
                 }
    """;

    public static final String GET_BATCH_BY_ID_RESPONSE_EXAMPLE = """
       {
                     "status": "success",
                     "meta": {
                         "code": 200,
                         "details": "Batches listed successfully",
                         "timestamp": "2025-01-28T16:25:53.9576133"
                     },
                     "data": {
                         "items": [
                             {
                                 "id": 55,
                                 "product_id": 17,
                                 "total_quantity": 11,
                                 "batch_code": "test",
                                 "expiry_date": "2025-04-27",
                                 "manufacture_date": "2025-01-27",
                                 "grn_item_id": 78,
                                 "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
                             },
                             {
                                 "id": 44,
                                 "product_id": 17,
                                 "total_quantity": 124,
                                 "batch_code": "123",
                                 "expiry_date": "2025-04-28",
                                 "manufacture_date": "2025-01-12",
                                 "grn_item_id": 62,
                                 "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
                             }
                         ],
                         "columns": {
                             "product_id": "PRODUCT ID",
                             "product_name": "PRODUCT NAME",
                             "brand_id": "BRAND ID",
                             "brand_name": "BRAND NAME",
                             "category_id": "CATEGORY ID",
                             "category_name": "CATEGORY NAME",
                             "total_quantity": "TOTAL QUANTITY",
                             "batch_code": "BATCH CODE",
                             "expiry_date": "EXPIRY DATE",
                             "grn_item_id": "GRN ITEM ID",
                             "manufacture_date": "MANUFACTURE DATE"
                         }
                     }
                 }
    """;

    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 Annotations for APIs
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_INVENTORIES_SUMMARY,
            description = GET_ALL_INVENTORIES_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Inventories listed successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_ALL_INVENTORIES_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllInventoriesOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_BATCH_BY_ID_SUMMARY,
            description = GET_BATCH_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Batch retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_BATCH_BY_ID_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetBatchByIdOperation {}
}
