package com.nebula.erp.product.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.responses.ApiResponse;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

public class CommonSwagger {

    // Summaries and Descriptions
    public static final String GET_IMAGE_SUMMARY = "Retrieve an uploaded image";
    public static final String GET_IMAGE_DESCRIPTION = "Fetch an image file from the uploads directory by its filename.";

    // Example Responses
    public static final String GET_IMAGE_EXAMPLE = """
        {
            "status": "success",
            "meta": {
                "code": 200,
                "message": "Image retrieved successfully"
            },
            "data": {
                "filename": "example.jpg",
                "content_type": "image/jpeg"
            }
        }
    """;

    public static final String IMAGE_NOT_FOUND_EXAMPLE = """
        {
            "status": "error",
            "meta": {
                "code": 404, 
                "message": "Image not found"
            }
        }
    """;

    public static final String INTERNAL_SERVER_ERROR_EXAMPLE = """
        {
            "status": "error",
            "meta": {
                "code": 500,
                "message": "An internal server error occurred"
            }
        }
    """;



    // Annotation for the GetImage API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_IMAGE_SUMMARY,
            description = GET_IMAGE_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Image retrieved successfully",
                            content = @Content(
                                    mediaType = "image/jpeg",
                                    examples = @ExampleObject(value = GET_IMAGE_EXAMPLE)
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Image not found",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = IMAGE_NOT_FOUND_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetImageOperation {}

    // Annotation for Global Error Response (500 Internal Server Error)
    @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 {}
}
