import { Body, Controller, Post } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { SearchService } from './search.service';
import { SearchTripsDto, FareQuoteDto } from './search.dto';

@ApiTags('Search')
@Controller('search')
export class SearchController {
  constructor(private service: SearchService) {}

  @Post()
  @ApiOperation({
    summary: 'Search trips by origin, destination, date, passengers, and nationality',
    description: `Finds all train schedules matching search criteria with real-time seat availability.

- Any origin→destination stop pair (not just terminals)
- Age-based passenger counts (adults ≥5 years, children <5 years)
- Nationality filtering (Ethiopian, Djiboutian, Other)
- Real-time seat availability per class
- Multi-currency fare display
- Example: Train A→B→C→D appears in results for A→B, A→C, A→D, B→C, B→D, C→D
- Availability: Segment-based (seat booked A→B is still available B→D)`
  })
  @ApiResponse({ status: 200, description: 'Matching schedules with segment-accurate seat availability per class' })
  searchTrips(@Body() dto: SearchTripsDto) {
    return this.service.searchTrips(dto);
  }

  @Post('fare-quote')
  @ApiOperation({
    summary: 'Get fare quote with age-based pricing and multi-currency support',
    description: `Calculates detailed fare breakdown for a specific schedule leg.

Age-Based Pricing:
- ADULT (≥5 years): 100% of base fare
- CHILD (<5 years): First child FREE, subsequent children 100%
- Example: 2 adults + 3 children = 4× base fare

Pricing Rules (priority order):
1. Schedule-scoped FareRule (tripId = scheduleId)
2. Segment route FareRule (e.g. ADD-DRE)
3. Full-route FareRule (e.g. ADD-DJI)
4. Default hardcoded fare

Multi-Currency:
- Transaction currency: ETB
- Display currencies: ETB, DJF, USD
- Real-time exchange rate conversion

Nationality-Based:
- Ethiopian: National ID verification required
- Djiboutian: Passport details, Waafi payment available
- Other: Passport details, international payments`
  })
  @ApiResponse({ status: 200, description: 'Fare breakdown with adult/child pricing, discounts, taxes, and currency conversion' })
  @ApiResponse({ status: 404, description: 'Schedule not found or origin/destination not on schedule' })
  getFareQuote(@Body() dto: FareQuoteDto) {
    return this.service.getFareQuote(dto);
  }
}
