package com.nebula.erp.purchase.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 DebitNoteSwagger {

    // Summaries and Descriptions
    public static final String CREATE_DEBIT_NOTE_SUMMARY = "Create a new debit note";
    public static final String CREATE_DEBIT_NOTE_DESCRIPTION = "Creates a new debit note, including refund details, supplier, and reason.";

    public static final String GET_DEBIT_NOTE_BY_ID_SUMMARY = "Retrieve debit note by ID";
    public static final String GET_DEBIT_NOTE_BY_ID_DESCRIPTION = "Retrieves details of a specific debit note using its unique ID.";

    public static final String GET_ALL_DEBIT_NOTES_SUMMARY = "Retrieve all debit notes";
    public static final String GET_ALL_DEBIT_NOTES_DESCRIPTION = "Retrieves all debit notes with pagination and optional filters.";

    // Example Requests
    public static final String CREATE_DEBIT_NOTE_REQUEST_EXAMPLE = """
        {
                    "debit_note_id":"DN-1",
                    "invoice_id":"PR-1",
                    "supplier_id":"1",
                    "date": "2024-08-31T10:00:00",
                    "grn_id":2,
                    "purchase_return_id":1,
                    "reason":"test",
                    "refund_amount":1.00,
                    "discount_amount":0.00,
                    "payment_method":"Cash"
                }
    """;

    // Example Responses
    public static final String CREATE_DEBIT_NOTE_RESPONSE_EXAMPLE = """
        {
                    "status": "success",
                    "meta": {
                        "code": 201,
                        "details": "Debit note created successfully",
                        "timestamp": "2025-01-28T15:21:32.6871132"
                    },
                    "data": {
                        "id": 8,
                        "debit_note_id": "CN-62",
                        "invoice_id": "SR-27",
                        "supplier_id": 27,
                        "date": "2025-01-27T18:30:00",
                        "grn_id": 62,
                        "purchase_return_id": 27,
                        "debit_amount": 708.0,
                        "refund_amount": 600.0,
                        "discount_amount": 100.0,
                        "reason": "tests",
                        "payment_method": "credit_card",
                        "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                        "tenant": "Arise_Tenant",
                        "created_at": "2025-01-28T15:21:32.6714835",
                        "updated_at": "2025-01-28T15:21:32.6714835",
                        "deleted_at": null
                    }
                }
    """;

    public static final String GET_DEBIT_NOTE_BY_ID_RESPONSE_EXAMPLE = """
       {
                   "status": "success",
                   "meta": {
                       "code": 201,
                       "details": "Debit note retrieved successfully",
                       "timestamp": "2025-01-28T15:18:05.0413427"
                   },
                   "data": {
                       "id": 7,
                       "debit_note_id": "CN-63",
                       "invoice_id": "SR-28",
                       "supplier_id": 28,
                       "date": "2024-12-30T18:30:00",
                       "grn_id": 63,
                       "purchase_return_id": 28,
                       "debit_amount": 14.16,
                       "refund_amount": 11.0,
                       "discount_amount": 0.0,
                       "payment_method": "debit_card",
                       "reason": "test",
                       "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                       "created_at": "2025-01-24T10:16:12.303423",
                       "columns": {
                           "id": "ID",
                           "debit_note_id": "DEBIT NOTE ID",
                           "invoice_id": "INVOICE ID",
                           "supplier_id": "SUPPLIER ID",
                           "date": "DATE",
                           "grn_id": "GRN ID",
                           "purchase_return_id": "PURCHASE RETURN ID",
                           "debit_amount": "DEBIT AMOUNT",
                           "refund_amount": "REFUND AMOUNT",
                           "discount_amount": "DISCOUNT AMOUNT",
                           "payment_method": "PAYMENT METHOD",
                           "reason": "REASON",
                           "created_by": "CREATED BY",
                           "created_at": "CREATED AT"
                       }
                   }
               }
    """;

    public static final String GET_ALL_DEBIT_NOTES_RESPONSE_EXAMPLE = """
        {
                     "status": "success",
                     "meta": {
                         "code": 200,
                         "details": "Debit notes retrieved successfully",
                         "timestamp": "2025-01-28T15:17:30.0953549"
                     },
                     "data": {
                         "pagination": {
                             "current_page": 1,
                             "per_page": 10,
                             "total": 1,
                             "last_page": 1,
                             "next_page_url": null,
                             "prev_page_url": null
                         },
                         "items": [
                             {
                                 "id": 7,
                                 "debit_note_id": "CN-63",
                                 "invoice_id": "SR-28",
                                 "supplier_id": 28,
                                 "date": "2024-12-30T18:30:00",
                                 "grn_id": 63,
                                 "purchase_return_id": 28,
                                 "debit_amount": 14.16,
                                 "refund_amount": 11.0,
                                 "discount_amount": 0.0,
                                 "reason": "test",
                                 "payment_method": "debit_card",
                                 "created_by": "0d5d2ca9-87ac-4a06-afde-d6f665a23be8",
                                 "tenant": "Arise_Tenant",
                                 "created_at": "2025-01-24T10:16:12.303423",
                                 "updated_at": "2025-01-24T10:16:12.303423",
                                 "deleted_at": null
                             }
                         ],
                         "columns": {
                             "id": "ID",
                             "debit_note_id": "DEBIT NOTE ID",
                             "invoice_id": "INVOICE ID",
                             "supplier_id": "SUPPLIER ID",
                             "date": "DATE",
                             "grn_id": "GRN ID",
                             "purchase_return_id": "PURCHASE RETURN ID",
                             "debit_amount": "DEBIT AMOUNT",
                             "refund_amount": "REFUND AMOUNT",
                             "discount_amount": "DISCOUNT AMOUNT",
                             "payment_method": "PAYMENT METHOD",
                             "reason": "REASON",
                             "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 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 Each API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = CREATE_DEBIT_NOTE_SUMMARY,
            description = CREATE_DEBIT_NOTE_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.purchase.requestmodel.DebitRequest.class),
                            examples = @ExampleObject(value = CREATE_DEBIT_NOTE_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "201",
                            description = "Debit note created successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = CREATE_DEBIT_NOTE_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface CreateDebitNoteOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_DEBIT_NOTE_BY_ID_SUMMARY,
            description = GET_DEBIT_NOTE_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Debit note retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_DEBIT_NOTE_BY_ID_RESPONSE_EXAMPLE)
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Debit note not found",
                            content = @Content(mediaType = "application/json")
                    )
            }
    )
    public @interface GetDebitNoteByIdOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_DEBIT_NOTES_SUMMARY,
            description = GET_ALL_DEBIT_NOTES_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Debit notes retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_ALL_DEBIT_NOTES_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllDebitNotesOperation {}
}