/*
 * File: src/main/java/com/nebula/erp/product/document/ProductSwagger.java
 * Description: This class contains static constants that define the summaries,
 * descriptions, and example responses for the Product API documentation.
 */

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.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 ProductSwagger {

    // Summaries and Descriptions
    public static final String GET_ALL_PRODUCTS_SUMMARY = "Retrieve all products";
    public static final String GET_ALL_PRODUCTS_DESCRIPTION = "Fetch a paginated list of all products with optional filters like name, product ID, brand ID, and category ID.";

    public static final String CREATE_PRODUCT_SUMMARY = "Create a new product";
    public static final String CREATE_PRODUCT_DESCRIPTION = "Add a new product to the inventory, including optional images.";

    public static final String GET_PRODUCT_SUMMARY = "Retrieve product by ID";
    public static final String GET_PRODUCT_DESCRIPTION = "Fetch details of a specific product by its unique ID.";

    public static final String UPDATE_PRODUCT_SUMMARY = "Update a product";
    public static final String UPDATE_PRODUCT_DESCRIPTION = "Update product details, including its images.";

    //Example Requests
    public static final String CREATE_PRODUCT_REQUEST_EXAMPLE = """
            {
               "id": null,
               "name": "deprIC",
               "code": "DC-01",
               "brand_id": 74,
               "form": "tablet",
               "dosage": 10,
               "unit_of_measurement": "mg",
               "category_id": 31,
               "purchase_price": 2000,
               "selling_price": 2100,
               "mrp": 2100,
               "min_stock": 400,
               "tax_id": 13,
               "images": null,
               "description": "tests",
               "remarks": "test",
               "tenant": "Arise_Tenant",
               "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8"
            }
            
            """;

    public static final String UPDATE_PRODUCT_REQUEST_EXAMPLE = """
            {
               "id": 39,
               "name": "deprIC",
               "code": "DC-01",
               "brand_id": 74,
               "form": "tablet",
               "dosage": 10,
               "unit_of_measurement": "mg",
               "category_id": 31,
               "purchase_price": 2000,
               "selling_price": 2100,
               "mrp": 2100,
               "min_stock": 400,
               "tax_id": 13,
               "description": "tests",
               "remarks": "test",
               "tenant": "Arise_Tenant",
               "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8"
            }
            
            """;

    // Example Responses
    public static final String GET_ALL_PRODUCTS_EXAMPLE = """
            {
                "status": "Success",
                "meta": {
                    "code": 200,
                    "details": "Medications retrieved successfully.",
                    "timestamp": "2025-01-22T18:07:05.2883398"
                },
                "data": {
                    "pagination": {
                        "current_page": 1,
                        "per_page": 10,
                        "total": 3,
                        "last_page": 1,
                        "next_page_url": null,
                        "prev_page_url": null
                    },
                    "items": [
                        {
                            "id": 17,
                            "code": "1111",
                            "name": "Creatine",
                            "description": "",
                            "form": "tablet",
                            "dosage": "1",
                            "unit_of_measurement": "g",
                            "quantity": null,
                            "purchase_price": 100.00,
                            "selling_price": 150.00,
                            "mrp": 200.00,
                            "min_stock": 100,
                            "tax_id": 13,
                            "tax_type": "GST",
                            "tax_rate": 18.00,
                            "brand_id": 55,
                            "brand_name": "ON ",
                            "category_id": 31,
                            "category_name": "Tablet",
                            "images": [],
                            "remarks": "",
                            "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                            "created_at": "2025-01-11T16:07:08.06884",
                            "updated_at": "2025-01-11T16:07:08.06884"
                        }
                    ],
                    "columns": {
                        "id": "PRODUCT ID",
                        "code": "PRODUCT CODE",
                        "name": "PRODUCT NAME",
                        "brand_id": "BRAND ID",
                        "brand_name": "BRAND NAME",
                        "category_id": "CATEGORY ID",
                        "category_name": "CATEGORY NAME",
                        "created_at": "CREATED AT",
                        "updated_at": "UPDATED AT"
                    }
                }
            }
            """;

    public static final String CREATE_PRODUCT_EXAMPLE = """
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Medication created successfully",
                    "timestamp": "2025-01-22T18:03:30.0818679"
                },
                "data": {
                    "id": 32,
                    "code": "PH-01",
                    "name": "PharmT",
                    "description": "paracitamol tablets",
                    "brand": {
                        "id": 70,
                        "name": "PharmC",
                        "description": "PharmaC is a medical products company",
                        "image": "uploads\\\\3df7ce2f-a094-4b55-b4f7-3f2a68c34c6f_Screenshot_13-1-2025_105944_122.165.217.145.jpeg",
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-22T15:58:36.734098",
                        "updated_at": "2025-01-22T15:58:36.734098",
                        "deleted_at": "2025-01-22T15:58:36.734098"
                    },
                    "category": {
                        "id": 31,
                        "name": "Tablet",
                        "description": "",
                        "image": null,
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-11T13:09:05.652727",
                        "updated_at": "2025-01-11T13:09:05.652727",
                        "deleted_at": "2025-01-11T13:09:05.652727"
                    },
                    "form": "tablet",
                    "dosage": "10",
                    "unit_of_measurement": "mg",
                    "quantity": null,
                    "purchase_price": 7000,
                    "selling_price": 7900,
                    "mrp": 7900,
                    "min_stock": 500,
                    "tax": {
                        "id": 13,
                        "type": "GST",
                        "rate": 18.00,
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-02T11:14:48.636206",
                        "updated_at": "2025-01-02T11:14:48.636206",
                        "deleted_at": "2025-01-02T11:14:48.636206"
                    },
                    "remarks": "no",
                    "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                    "tenant": "Arise_Tenant",
                    "created_at": "2025-01-22T18:03:30.0508804",
                    "updated_at": "2025-01-22T18:03:30.0508804",
                    "deleted_at": "2025-01-22T18:03:30.0508804"
                }
            }
            """;

    public static final String GET_PRODUCT_EXAMPLE = """
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Medication retrieved successfully",
                    "timestamp": "2025-01-22T17:59:04.5250057"
                },
                "data": {
                    "id": 30,
                    "code": "DL-01",
                    "name": "DOLO",
                    "description": "paracitamol tablet",
                    "form": "tablet",
                    "dosage": "10",
                    "unit_of_measurement": "mg",
                    "quantity": null,
                    "purchase_price": 10000.00,
                    "selling_price": 11000.00,
                    "mrp": 11100.00,
                    "min_stock": 500,
                    "tax_id": 13,
                    "tax_type": "GST",
                    "tax_rate": 18.00,
                    "brand_id": 55,
                    "brand_name": "ON ",
                    "category_id": 31,
                    "category_name": "Tablet",
                    "images": [],
                    "remarks": "null",
                    "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                    "created_at": "2025-01-22T13:04:47.215535",
                    "updated_at": "2025-01-22T13:04:47.215535",
                    "tenant": "Arise_Tenant"
                }
            }
            """;

    public static final String UPDATE_PRODUCT_EXAMPLE = """
            {
                "status": "success",
                "meta": {
                    "code": 200,
                    "details": "Medication updated successfully",
                    "timestamp": "2025-01-22T18:09:05.4733146"
                },
                "data": {
                    "id": 32,
                    "code": "PH-01",
                    "name": "PharmT",
                    "description": "paracitamol tablets",
                    "brand": {
                        "id": 70,
                        "name": "PharmC",
                        "description": "PharmaC is a medical products company",
                        "image": "uploads\\\\3df7ce2f-a094-4b55-b4f7-3f2a68c34c6f_Screenshot_13-1-2025_105944_122.165.217.145.jpeg",
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-22T15:58:36.734098",
                        "updated_at": "2025-01-22T15:58:36.734098",
                        "deleted_at": "2025-01-22T15:58:36.734098"
                    },
                    "category": {
                        "id": 31,
                        "name": "Tablet",
                        "description": "",
                        "image": null,
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-11T13:09:05.652727",
                        "updated_at": "2025-01-11T13:09:05.652727",
                        "deleted_at": "2025-01-11T13:09:05.652727"
                    },
                    "form": "tablet",
                    "dosage": "10",
                    "unit_of_measurement": "mg",
                    "quantity": null,
                    "purchase_price": 7000,
                    "selling_price": 7900,
                    "mrp": 7900,
                    "min_stock": 500,
                    "tax": {
                        "id": 13,
                        "type": "GST",
                        "rate": 18.00,
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-02T11:14:48.636206",
                        "updated_at": "2025-01-02T11:14:48.636206",
                        "deleted_at": "2025-01-02T11:14:48.636206"
                    },
                    "remarks": "no",
                    "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                    "tenant": "Arise_Tenant",
                    "created_at": "2025-01-22T18:03:30.05088",
                    "updated_at": "2025-01-22T18:03:30.05088",
                    "deleted_at": "2025-01-22T18:03:30.05088"
                }
            }
            """;

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


    // 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 for Each API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_PRODUCTS_SUMMARY,
            description = GET_ALL_PRODUCTS_DESCRIPTION,
            responses = {
                    @ApiResponse(

                            responseCode = "200",
                            description = "Products retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = com.nebula.erp.product.utility.ApiResponse.class),
                                    examples = @ExampleObject(value = GET_ALL_PRODUCTS_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllProductsOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = CREATE_PRODUCT_SUMMARY,
            description = CREATE_PRODUCT_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.product.requestmodel.ProductRequest.class),
                            examples = @ExampleObject(value = CREATE_PRODUCT_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "201",
                            description = "Product created successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = com.nebula.erp.product.utility.ApiResponse.class),
                                    examples = @ExampleObject(value = CREATE_PRODUCT_EXAMPLE)
                            )
                    )
            }
    )
    public @interface CreateProductOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_PRODUCT_SUMMARY,
            description = GET_PRODUCT_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Product retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = com.nebula.erp.product.utility.ApiResponse.class),
                                    examples = @ExampleObject(value = GET_PRODUCT_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetProductOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = UPDATE_PRODUCT_SUMMARY,
            description = UPDATE_PRODUCT_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.product.requestmodel.ProductRequest.class),
                            examples = @ExampleObject(value = UPDATE_PRODUCT_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Product updated successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(implementation = com.nebula.erp.product.utility.ApiResponse.class),
                                    examples = @ExampleObject(value = UPDATE_PRODUCT_EXAMPLE)
                            )
                    )
            }
    )
    public @interface UpdateProductOperation {}
}
