import { api as client } from "../auth/http";

export interface AiExtractedBooking {
  customerName: string | null;
  origin: string | null;
  destination: string | null;
  cargoType: string | null;
  containerType: "20FT" | "40FT" | "BULK" | "RO_RO" | null;
  quantity: number | null;
  direction: "IMPORT" | "EXPORT" | null;
  weightKg: number | null;
  pickupRequired: boolean | null;
  deliveryRequired: boolean | null;
}

export interface AiValidationResult {
  valid: boolean;
  errors: string[];
}

export interface AiRecommendation {
  action: "CREATE_DRAFT_BOOKING" | "REQUEST_MISSING_INFORMATION";
  message: string;
  confidence: number;
}

export interface AiBookingExtractResult {
  provider: "mock";
  extracted: AiExtractedBooking;
  validation: AiValidationResult;
  recommendation: AiRecommendation;
}

interface AiBookingExtractResponse {
  success: boolean;
  data: AiBookingExtractResult;
  timestamp: string;
}

export const extractBookingFromText = async (
  text: string,
): Promise<AiBookingExtractResult> => {
  const response = await client.post<AiBookingExtractResponse>(
    "/ai/booking/extract",
    { text },
  );
  return response.data.data;
};
