package com.flightticket.aspect;

import com.flightticket.model.enums.RequestStatus;
import com.flightticket.model.enums.RequestType;
import org.junit.jupiter.api.Test;

import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Unit tests for AmadeusUsageAspect.
 * 
 * These tests verify the core logic and mappings used by the aspect:
 * - Request type mapping from method names
 * - Transaction ID pattern matching
 * - Response status values
 * 
 * Full integration testing of the aspect requires Spring AOP context
 * and is better suited for integration tests where:
 * - The aspect is woven into the Amadeus client
 * - Actual method calls trigger the aspect
 * - Usage logging is verified end-to-end
 * 
 * Requirements: 1.1, 1.2, 1.3, 1.4, 1.5
 */
class AmadeusUsageAspectTest {
    
    @Test
    void testRequestType_FlightSearch() {
        // Verify that FLIGHT_SEARCH request type exists and is correctly defined
        RequestType requestType = RequestType.FLIGHT_SEARCH;
        assertThat(requestType).isNotNull();
        assertThat(requestType.name()).isEqualTo("FLIGHT_SEARCH");
    }
    
    @Test
    void testRequestType_PriceCheck() {
        // Verify that PRICE_CHECK request type exists and is correctly defined
        RequestType requestType = RequestType.PRICE_CHECK;
        assertThat(requestType).isNotNull();
        assertThat(requestType.name()).isEqualTo("PRICE_CHECK");
    }
    
    @Test
    void testRequestType_PnrCreation() {
        // Verify that PNR_CREATION request type exists and is correctly defined
        RequestType requestType = RequestType.PNR_CREATION;
        assertThat(requestType).isNotNull();
        assertThat(requestType.name()).isEqualTo("PNR_CREATION");
    }
    
    @Test
    void testRequestType_BookingRetrieval() {
        // Verify that BOOKING_RETRIEVAL request type exists and is correctly defined
        RequestType requestType = RequestType.BOOKING_RETRIEVAL;
        assertThat(requestType).isNotNull();
        assertThat(requestType.name()).isEqualTo("BOOKING_RETRIEVAL");
    }
    
    @Test
    void testRequestType_BookingCancellation() {
        // Verify that BOOKING_CANCELLATION request type exists and is correctly defined
        RequestType requestType = RequestType.BOOKING_CANCELLATION;
        assertThat(requestType).isNotNull();
        assertThat(requestType.name()).isEqualTo("BOOKING_CANCELLATION");
    }
    
    @Test
    void testTransactionIdPattern_ValidUuid() {
        // Test that valid UUID format is recognized as transaction ID
        String transactionId = "123e4567-e89b-12d3-a456-426614174001";
        assertThat(transactionId).matches("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
    }
    
    @Test
    void testTransactionIdPattern_InvalidFormat() {
        // Test that invalid format is not recognized as transaction ID
        String invalidId = "not-a-uuid";
        assertThat(invalidId).doesNotMatch("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}");
    }
    
    @Test
    void testRequestStatus_Success() {
        // Verify that SUCCESS status exists and is correctly defined
        RequestStatus status = RequestStatus.SUCCESS;
        assertThat(status).isNotNull();
        assertThat(status.name()).isEqualTo("SUCCESS");
    }
    
    @Test
    void testRequestStatus_Failure() {
        // Verify that FAILURE status exists and is correctly defined
        RequestStatus status = RequestStatus.FAILURE;
        assertThat(status).isNotNull();
        assertThat(status.name()).isEqualTo("FAILURE");
    }
    
    @Test
    void testClientIdFormat() {
        // Verify that client IDs can be represented as UUIDs
        UUID clientId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
        assertThat(clientId).isNotNull();
        assertThat(clientId.toString()).isEqualTo("123e4567-e89b-12d3-a456-426614174000");
    }
}
