import type { AppliedDataSemantic } from '../Semantics.js'
import { SemanticType } from '../Semantics.js'

/**
 * Configuration options for the Description semantic.
 * Controls length, formatting, and markdown support.
 */
export interface DescriptionConfig {
  /**
   * Custom metadata for the description field.
   */
  metadata?: Record<string, unknown>
  /**
   * Index signature to allow additional properties.
   */
  [key: string]: unknown
}

/**
 * Type-safe configuration for Description semantic.
 */
export interface AppliedDescriptionSemantic extends AppliedDataSemantic {
  id: SemanticType.Description
  config?: DescriptionConfig
}

/**
 * Type guard to check if a semantic is a Description semantic.
 */
export const isDescriptionSemantic = (semantic: AppliedDataSemantic): semantic is AppliedDescriptionSemantic => {
  return semantic.id === SemanticType.Description
}

/**
 * Helper function to create a Description semantic with configuration.
 */
export const createDescriptionSemantic = (config: DescriptionConfig = {}): AppliedDescriptionSemantic => {
  const mergedConfig = {
    ...DEFAULT_DESCRIPTION_CONFIG,
    ...config,
  }
  if (config.metadata) {
    mergedConfig.metadata = { ...config.metadata }
  }

  return {
    id: SemanticType.Description,
    config: mergedConfig,
  }
}

/**
 * Default configuration for Description semantic.
 */
export const DEFAULT_DESCRIPTION_CONFIG: DescriptionConfig = {}
