package com.flightticket.service;

import com.flightticket.dto.expedia.ExpediaBookingRequest;
import com.flightticket.dto.expedia.ExpediaBookingResponse;
import com.flightticket.dto.expedia.ExpediaPriceCheckResponse;
import com.flightticket.dto.expedia.ExpediaShopRequest;
import com.flightticket.dto.expedia.ExpediaShopResponse;
import com.flightticket.exception.PriceChangedException;

import java.util.List;
import java.util.UUID;

/**
 * Service interface for Expedia booking operations
 * Orchestrates the three-step booking workflow: Shop → Price Check → Book
 * Integrates with wallet service for payment processing using Hold & Resume pattern
 * 
 * Requirements: 2.1, 3.1, 4.1
 */
public interface ExpediaBookingService {
    
    /**
     * Step 1: Search for available accommodations
     * Calls Expedia Shop API and caches price_check links for each room
     * 
     * Requirements: 2.1, 2.2, 2.3, 2.4
     * 
     * @param request Search parameters (location, dates, occupancy)
     * @return List of available rooms with pricing and details
     */
    List<ExpediaShopResponse.ExpediaRoom> searchAvailability(ExpediaShopRequest request);
    
    /**
     * Step 2: Validate room availability and lock price
     * Retrieves cached price_check link and calls Expedia Price Check API
     * If price matches, caches the book link for the next step
     * If price has changed, throws PriceChangedException with old and new prices
     * 
     * Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 7.1, 7.2, 7.3, 7.5
     * 
     * @param roomId Unique room identifier from search results
     * @return Price check result with status and pricing information
     * @throws PriceChangedException if the room price has changed since search
     */
    ExpediaPriceCheckResponse validatePrice(String roomId) throws PriceChangedException;
    
    /**
     * Step 3: Book room with hold and payment processing
     * Orchestrates the complete booking flow:
     * 1. Retrieves cached book link from price check step
     * 2. Creates hold booking with Expedia (hold=true)
     * 3. Reserves funds in the agency's wallet
     * 4. Debits the wallet for the booking amount
     * 5. If payment succeeds: resumes booking with Expedia to confirm
     * 6. If payment fails: cancels the hold booking
     * 7. Cleans up cached links after completion
     * 
     * Requirements: 4.1, 4.2, 4.3, 4.4, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 6.6
     * 
     * @param roomId Unique room identifier from search results
     * @param request Booking details (travelers, payment info, contact details)
     * @param agencyId Agency ID for wallet operations
     * @param userId User ID who is creating the booking
     * @return Final booking response with confirmation number and details
     */
    ExpediaBookingResponse bookRoom(String roomId, ExpediaBookingRequest request, UUID agencyId, UUID userId);
}
