package com.nebula.erp.sales.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 CreditNoteSwagger {

    // Summaries and Descriptions
    public static final String CREATE_CREDIT_NOTE_SUMMARY = "Create a new credit note";
    public static final String CREATE_CREDIT_NOTE_DESCRIPTION = "API to create a new credit note, including refund details and reasons for the credit.";

    public static final String GET_CREDIT_NOTE_BY_ID_SUMMARY = "Retrieve credit note by ID";
    public static final String GET_CREDIT_NOTE_BY_ID_DESCRIPTION = "API to retrieve a specific credit note by its unique ID.";

    public static final String GET_ALL_CREDIT_NOTES_SUMMARY = "Retrieve all credit notes";
    public static final String GET_ALL_CREDIT_NOTES_DESCRIPTION = "API to retrieve a paginated list of all credit notes, with optional filters by sales return ID.";

    // Request Examples
    public static final String CREATE_CREDIT_NOTE_REQUEST_EXAMPLE = """
        {
                    "credit_note_id":"CN-1",
                    "invoice_id":"SR-1",
                    "date": "2024-08-31T10:00:00",
                    "sales_id":22,
                    "sales_return_id":22,
                    "reason":"test",
                    "refund_amount":1.00,
                    "discount_amount":0.00,
                    "payment_method":"Cash"
                }
    """;

    // Response Examples
    public static final String CREATE_CREDIT_NOTE_RESPONSE_EXAMPLE = """
        {
            "status": "success",
            "meta": {
                "code": 201,
                "message": "Credit note created successfully"
            },
            "data": {
                "id": 1,
                "credit_note_id": "CR12345",
                "invoice_id": "INV789",
                "sales_id": 101,
                "sales_return_id": 301,
                "credit_amount": 1000.00,
                "refund_amount": 200.00,
                "discount_amount": 50.00,
                "payment_method": "Cash",
                "reason": "Damaged product return",
                "created_at": "2025-01-28T12:00:00Z",
                "created_by": "admin"
            }
        }
    """;

    public static final String GET_CREDIT_NOTE_RESPONSE_EXAMPLE = """
        {
            "status": "success",
            "meta": {
                "code": 200,
                "message": "Credit note retrieved successfully"
            },
            "data": {
                "id": 1,
                "credit_note_id": "CR12345",
                "invoice_id": "INV789",
                "sales_id": 101,
                "sales_return_id": 301,
                "credit_amount": 1000.00,
                "refund_amount": 200.00,
                "discount_amount": 50.00,
                "payment_method": "Cash",
                "reason": "Damaged product return",
                "created_at": "2025-01-28T12:00:00Z",
                "created_by": "admin"
            }
        }
    """;

    public static final String GET_ALL_CREDIT_NOTES_RESPONSE_EXAMPLE = """
        {
            "status": "success",
            "meta": {
                "code": 200,
                "message": "Credit notes retrieved successfully"
            },
            "data": {
                "pagination": {
                    "current_page": 1,
                    "per_page": 10,
                    "total": 50,
                    "last_page": 5
                },
                "items": [
                    {
                        "id": 1,
                        "credit_note_id": "CR12345",
                        "invoice_id": "INV789",
                        "sales_id": 101,
                        "sales_return_id": 301,
                        "credit_amount": 1000.00,
                        "refund_amount": 200.00,
                        "discount_amount": 50.00,
                        "payment_method": "Cash",
                        "reason": "Damaged product return",
                        "created_at": "2025-01-28T12:00:00Z",
                        "created_by": "admin"
                    }
                ]
            }
        }
    """;

    public static final String INTERNAL_SERVER_ERROR_EXAMPLE = """
        {
            "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_EXAMPLE)
            )
    )
    public @interface GlobalErrorResponse {}

    // Modular Annotations for Each API
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = CREATE_CREDIT_NOTE_SUMMARY,
            description = CREATE_CREDIT_NOTE_DESCRIPTION,
            requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
                    content = @Content(
                            mediaType = "application/json",
                            schema = @Schema(implementation = com.nebula.erp.sales.requestmodel.CreditRequest.class),
                            examples = @ExampleObject(value = CREATE_CREDIT_NOTE_REQUEST_EXAMPLE)
                    )
            ),
            responses = {
                    @ApiResponse(
                            responseCode = "201",
                            description = "Credit note created successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = CREATE_CREDIT_NOTE_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface CreateCreditNoteOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_CREDIT_NOTE_BY_ID_SUMMARY,
            description = GET_CREDIT_NOTE_BY_ID_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Credit note retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_CREDIT_NOTE_RESPONSE_EXAMPLE)
                            )
                    ),
                    @ApiResponse(
                            responseCode = "404",
                            description = "Credit note not found",
                            content = @Content(mediaType = "application/json")
                    )
            }
    )
    public @interface GetCreditNoteByIdOperation {}

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Operation(
            summary = GET_ALL_CREDIT_NOTES_SUMMARY,
            description = GET_ALL_CREDIT_NOTES_DESCRIPTION,
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "Credit notes retrieved successfully",
                            content = @Content(
                                    mediaType = "application/json",
                                    examples = @ExampleObject(value = GET_ALL_CREDIT_NOTES_RESPONSE_EXAMPLE)
                            )
                    )
            }
    )
    public @interface GetAllCreditNotesOperation {}
}