import { apiGet, apiPost } from "./client";

export interface OnboardingStatus {
  completed: boolean;
}

export interface BreakglassAdminRequest {
  username: string;
  password: string;
}

export interface BreakglassAdminResponse {
  id: string;
  username: string;
}

export interface ConfigureOidcRequest {
  issuerUrl: string;
  clientId: string;
  clientSecret: string;
}

export interface ProviderModel {
  id: string;
  name?: string;
}

export interface AddOnboardingProviderRequest {
  name: string;
  displayName: string;
  type: string;
  baseUrl?: string;
  apiKey?: string;
  models?: ProviderModel[];
}

export interface AddOnboardingProviderResponse {
  id: string;
}

export interface TestOnboardingProviderRequest {
  type: string;
  baseUrl?: string;
  apiKey?: string;
}

export interface TestOnboardingProviderResponse {
  success: boolean;
  error?: string;
}

export async function fetchOnboardingStatus(): Promise<OnboardingStatus> {
  return apiGet<OnboardingStatus>("/api/onboarding/status");
}

export async function createBreakglassAdmin(
  request: BreakglassAdminRequest
): Promise<BreakglassAdminResponse> {
  return apiPost<BreakglassAdminResponse>("/api/onboarding/breakglass", request);
}

export async function configureOidcProvider(request: ConfigureOidcRequest): Promise<void> {
  await apiPost<unknown>("/api/onboarding/oidc", request);
}

export async function addOnboardingProvider(
  request: AddOnboardingProviderRequest
): Promise<AddOnboardingProviderResponse> {
  return apiPost<AddOnboardingProviderResponse>("/api/onboarding/provider", request);
}

export async function testOnboardingProvider(
  request: TestOnboardingProviderRequest
): Promise<TestOnboardingProviderResponse> {
  return apiPost<TestOnboardingProviderResponse>("/api/onboarding/provider/test", request);
}

export async function completeOnboarding(): Promise<void> {
  await apiPost<unknown>("/api/onboarding/complete");
}
