export type KnowledgeBaseType = 'document' | 'faq'

export interface ParserEngineRule {
	engine: string
	file_types: string[]
}

/** Knowledge base detail returned by the backend. */
export interface KnowledgeBaseConfig {
	asr_config?: { enabled: boolean; language: string; model_id: string }
	chunking_config?: {
		child_chunk_size: number
		chunk_overlap: number
		chunk_size: number
		enable_parent_child: boolean
		parent_chunk_size: number
		parser_engine_rules: ParserEngineRule[]
		separators: string[]
	}
	creationTime?: string
	creatorUserId?: string
	description?: string
	embedding_model_id?: string
	faq_config?: {
		index_mode: string
		question_index_mode: string
	}
	id: string
	indexing_strategy?: {
		graph_enabled: boolean
		keyword_enabled: boolean
		vector_enabled: boolean
		wiki_enabled: boolean
	}
	isDeleted?: boolean
	is_pinned?: boolean
	is_temporary?: boolean
	name: string
	question_generation_config?: { enabled: boolean; question_count: number }
	storage_config?: { provider: string }
	storage_provider_config?: { provider: string }
	summary_model_id?: string
	type: KnowledgeBaseType
	updateTime?: string
	vlm_config?: { enabled: boolean; model_id: string }
	wiki_config?: {
		extraction_granularity: string
		max_pages_per_ingest: number
		synthesis_model_id: string
	}
}

export type KnowledgeBaseItem = KnowledgeBaseConfig

/** Drawer form model for creating or editing a knowledge base. */
export interface KnowledgeBaseForm {
	name: string
	description: string
	type: KnowledgeBaseType
	embedding_model_id: string
	summary_model_id: string
	faq_index_mode: string
	faq_question_index_mode: string
	vlm_enabled: boolean
	vlm_model_id: string
	asr_enabled: boolean
	asr_model_id: string
	asr_language: string
	graph_enabled: boolean
	keyword_enabled: boolean
	vector_enabled: boolean
	wiki_enabled: boolean
	question_generation_enabled: boolean
	question_count: number
	chunk_size: number
	chunk_overlap: number
	separators: string[]
	parser_engine_rules: ParserEngineRule[]
	enable_parent_child: boolean
	parent_chunk_size: number
	child_chunk_size: number
	storage_provider: string
	wiki_extraction_granularity: string
	wiki_max_pages_per_ingest: number
	wiki_synthesis_model_id: string
}

/** Knowledge content row returned by the backend list API. */
export interface KnowledgeItem {
	channel?: string
	creationTime?: string
	description?: string
	embedding_model_id?: string
	enable_status?: string
	error_message?: string
	file_hash?: string
	file_name?: string
	file_path?: string
	file_size?: number
	file_type?: string
	id?: string
	isDeleted?: boolean
	knowledge_base_id?: string
	metadata?: Record<string, any>
	parse_status?: string
	source?: string
	storage_size?: number
	summary_status?: string
	tag_id?: string
	title?: string
	type?: string
	updateTime?: string
}

/** Form model for editing a single knowledge record. */
export interface KnowledgeEditForm {
	id: string
	title: string
	description: string
}

/** Form model for manually creating a knowledge record. */
export interface ManualKnowledgeForm {
	title: string
	content: string
	publish: boolean
}

/** Form model for importing a file-based knowledge record. */
export interface FileKnowledgeForm {
	enable_multi_model: boolean
	metadata: MetadataEntry[]
}

export interface MetadataEntry {
	key: string
	value: string
}

/** FAQ row returned by the backend list API. */
export interface FaqItem {
	answer_strategy?: string
	answers?: string[]
	chunk_id?: string
	chunk_type?: string
	creationTime?: string
	creatorUserId?: string
	id?: string
	index_mode?: string
	is_enabled?: boolean
	is_recommended?: boolean
	knowledge_base_id?: string
	knowledge_id?: string
	negative_questions?: string[]
	similar_questions?: string[]
	standard_question?: string
	tag_id?: string
}

/** Form model for creating or editing an FAQ item. */
export interface FaqForm {
	id?: string
	standard_question: string
	similar_questions: string[]
	negative_questions: string[]
	answers: string[]
	is_enabled: boolean
}

/** Minimal model option used by knowledge forms. */
export interface KnowledgeModelOption {
	id: string
	name: string
	title: string
	type: string
	provider: string
	source: string
	status?: string
}
