import type { Role } from './organization'
import type { UuidNameRef } from './common'

export type OnboardingField = {
    uuid: string
    key: string
    label: string
    field_type: 'text' | 'textarea' | 'select' | 'multiselect' | 'number' | 'boolean' | 'date'
    required: boolean
    help_text?: string
    placeholder?: string
    options?: string[]
    default_value?: unknown
    validation?: Record<string, unknown>
}

export type OnboardingPage = {
    uuid: string
    order: number
    title: string
    body?: string
    meta?: Record<string, unknown>
    fields: OnboardingField[]
}

export type OnboardingFlow = {
    uuid: string
    role: string | UuidNameRef
    agent?: string | null
    title: string
    description?: string
    pages?: OnboardingPage[]
}

export type OnboardingSession = {
    uuid: string
    status: OnboardingSessionStatus | string
    role?: string | UuidNameRef
    flow?: {
        uuid: string
        title?: string
        is_active?: boolean
    } | null
    state?: Record<string, unknown>
    active_configs?: Record<string, unknown>
    completed_at?: string | null
}

export type OnboardingFeedback = {
    summary?: string
}

export type OnboardingSessionStatus = 'active' | 'completed' | 'paused'

export type OnboardingSessionSummary = {
    uuid: string
    status: string
    role?: string | UuidNameRef
}

export type OnboardingFlowSummary = {
    uuid: string
    role?: string | UuidNameRef
}

export type ProgressSessionApi = {
    uuid: string
    status: OnboardingSessionStatus
    role: UuidNameRef
    user?: {
        uuid: string
        email_address?: string
        first_name?: string
        last_name?: string
    }
    updated_at?: string
    state?: Record<string, unknown>
}

export type ProgressFlowApi = {
    uuid: string
    role: UuidNameRef
    title: string
}

export type RoleProgressItem = {
    role: Role
    latestStatus: string
    latestSessionUuid?: string
    flowTitle?: string
    feedback?: string
    loadingFeedback: boolean
}

export type ProgressOverviewItem = {
    role: UuidNameRef
    user: {
        uuid: string
        name: string
        email: string
    }
    flow: {
        uuid: string
        title: string
        is_active: boolean
    }
    latest_status: string
    progress: number
    is_completed: boolean
    latest_session_uuid?: string | null
    updated_at?: string | null
}

export type FlowLookup = {
    title?: string
}
