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

    // Summaries and Descriptions
    public static final String ADD_STOCK_SUMMARY = "Add stock";
    public static final String ADD_STOCK_DESCRIPTION = "Adds stock to the inventory.";

    public static final String REDUCE_STOCK_SUMMARY = "Reduce stock";
    public static final String REDUCE_STOCK_DESCRIPTION = "Reduces stock from the inventory.";

    // Request and Response Examples
    public static final String ADD_STOCK_REQUEST_EXAMPLE = """
        {
                    "product_id": 10,
                    "quantity": 100,
                    "batch_code": 123,
                    "expiry_date": "2024-08-31T10:00:00",
                    "manufacture_date": "2024-08-31T10:00:00",
                    "grn_item_id":1,
                    "reason":"Purchase"
                }
    """;

    public static final String ADD_STOCK_RESPONSE_EXAMPLE = """
        {
                    "status": "success",
                    "meta": {
                        "code": 200,
                        "details": "Stock added successfully",
                        "timestamp": "2025-01-28T16:33:07.6646161"
                    },
                    "data": null
                }
    """;

    public static final String REDUCE_STOCK_REQUEST_EXAMPLE = """
        {
                    "product_id": 1,
                    "quantity": 1,
                    "reason":"SALES"
                }
    """;

    public static final String REDUCE_STOCK_RESPONSE_EXAMPLE = """
        {
                    "status": "success",
                    "meta": {
                        "code": 200,
                        "details": "Stock reduced successfully",
                        "timestamp": "2025-01-28T16:34:10.1766857"
                    },
                    "data": [
                        {
                            "quantity": 1,
                            "product_id": 10,
                            "batch_code": "123"
                        }
                    ]
                }
    """;

    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 = ADD_STOCK_SUMMARY,
            description = ADD_STOCK_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.inventory.requestmodel.StockRequest.class),
                            examples = @ExampleObject(value = ADD_STOCK_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Stock added successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = ADD_STOCK_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface AddStockOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = REDUCE_STOCK_SUMMARY,
            description = REDUCE_STOCK_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.inventory.requestmodel.StockRequest.class),
                            examples = @ExampleObject(value = REDUCE_STOCK_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Stock reduced successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = REDUCE_STOCK_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface ReduceStockOperation {}
}
