/**
 * Bot types for BoostBot Admin
 * @since 1.1.0
 */

export interface Bot {
    id: number
    bot_name: string
    bot_slug: string
    description: string | null
    is_active: boolean | number | string
    test_mode: boolean | number | string
    is_default: boolean | number | string
    welcome_message: string | null
    show_welcome_message: boolean | number | null
    position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
    
    // Appearance preset
    appearance_preset_id: number | null
    
    // Opening screen preset
    opening_screen_preset_id: number | null
    /**
     * Per-bot opening screen configuration overrides (JSON).
     * When present, the bot uses these settings instead of inheriting from the preset.
     */
    opening_screen_overrides?: Record<string, unknown> | string | null
    
    // WooCommerce preset
    woocommerce_preset_id: number | null
    
    // Colors
    primary_color: string | null
    secondary_color: string | null
    background_color: string | null
    header_background: string | null
    header_text_color: string | null
    user_message_bg: string | null
    user_message_text: string | null
    bot_message_bg: string | null
    bot_message_text: string | null
    input_bg: string | null
    input_text: string | null
    input_border: string | null
    button_bg: string | null
    button_text: string | null
    button_hover_bg: string | null
    link_color: string | null
    
    // Typography
    font_family: string | null
    font_size_base: string | null
    font_size_header: string | null
    font_weight_normal: string | null
    font_weight_bold: string | null
    line_height: string | null
    letter_spacing: string | null
    
    // Bubble
    bubble_icon: string | null
    bubble_size: string | null
    bubble_custom_icon: string | null
    bubble_animation: string | null
    
    // Window
    window_width: string | null
    window_height: string | null
    window_border_radius: string | null
    window_shadow: string | null
    
    // Custom CSS
    custom_css: string | null
    
    // Appearance overrides
    appearance_overrides: AppearanceOverrides | null
    
    // Behavior / Personality
    personality_id: number | null
    system_prompt: string | null
    tone: string | null
    proactive_engagement: boolean | number | null
    proactive_delay_seconds: number | null
    personality_overrides: PersonalityOverrides | null
    personality_traits: string[] | null
    custom_instructions: string | null
    rules: string | null
    forbidden_topics: string | null
    display_conditions: DisplayCondition[] | null
    priority: number
    knowledge_files: string[] | null
    attachment_files: string[] | null
    enabled_coupons: string[] | null
    contact_list_id: number | null
    enabled_widgets: string[] | null
    // Week 28: per-bot output cap (chars). Null means "use global".
    bot_output_char_limit?: number | null

    // Week 27.6: BrandCard override (per-bot)
    brand_card_mode?: 'global' | 'override' | null
    brand_card_override?: Record<string, unknown> | null
    created_at: string
    updated_at: string
    created_by: number | null
}

export interface DisplayCondition {
    id: string
    type: 'page' | 'post_type' | 'taxonomy' | 'url_contains' | 'all' | 'homepage'
    operator: 'include' | 'exclude'
    value?: string | number | number[]
}

// Personality overrides - tracks which personality fields are manually set vs inherited from personality
export interface PersonalityOverrides {
    system_prompt?: boolean
    tone?: boolean
    proactive_engagement?: boolean
    proactive_delay_seconds?: boolean
    custom_instructions?: boolean
    rules?: boolean
    forbidden_topics?: boolean
}

// Appearance overrides - tracks which appearance fields are manually set vs inherited from preset
export interface AppearanceOverrides {
    primary_color?: boolean
    secondary_color?: boolean
    background_color?: boolean
    header_background?: boolean
    header_text_color?: boolean
    user_message_bg?: boolean
    user_message_text?: boolean
    bot_message_bg?: boolean
    bot_message_text?: boolean
    input_bg?: boolean
    input_text?: boolean
    input_border?: boolean
    button_bg?: boolean
    button_text?: boolean
    button_hover_bg?: boolean
    link_color?: boolean
    font_family?: boolean
    font_size_base?: boolean
    font_size_header?: boolean
    font_weight_normal?: boolean
    font_weight_bold?: boolean
    line_height?: boolean
    letter_spacing?: boolean
    bubble_size?: boolean
    bubble_icon?: boolean
    bubble_animation?: boolean
    window_width?: boolean
    window_height?: boolean
    window_border_radius?: boolean
    window_shadow?: boolean
    custom_css?: boolean
}

// Default appearance values
export const DEFAULT_APPEARANCE = {
    primary_color: '#3BC2D0',
    secondary_color: '#E32774',
    background_color: '#FFFFFF',
    header_background: '#3BC2D0',
    header_text_color: '#FFFFFF',
    user_message_bg: '#3BC2D0',
    user_message_text: '#FFFFFF',
    bot_message_bg: '#F3F4F6',
    bot_message_text: '#1F2937',
    input_bg: '#FFFFFF',
    input_text: '#1F2937',
    input_border: '#E5E7EB',
    button_bg: '#3BC2D0',
    button_text: '#FFFFFF',
    button_hover_bg: '#2BA8B5',
    link_color: '#3BC2D0',
    font_family: 'inherit',
    font_size_base: '14px',
    font_size_header: '18px',
    font_weight_normal: '400',
    font_weight_bold: '600',
    line_height: '1.5',
    letter_spacing: 'normal',
    bubble_size: '60px',
    bubble_icon: 'robot',
    bubble_custom_icon: '',
    bubble_animation: 'none',
    window_width: '380px',
    window_height: '600px',
    window_border_radius: '16px',
    window_shadow: '0 10px 40px rgba(0,0,0,0.15)',
    custom_css: '',
}

export interface BotFormData {
    bot_name: string
    bot_slug: string
    description: string
    is_active: boolean
    test_mode: boolean
    is_default: boolean
    welcome_message: string
    show_welcome_message: boolean
    position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
    
    // Appearance preset
    appearance_preset_id: number | null
    
    // Opening screen preset
    opening_screen_preset_id: number | null

    /**
     * Per-bot opening screen configuration overrides (JSON).
     * When present, the bot uses these settings instead of inheriting from the preset.
     */
    opening_screen_overrides: Record<string, unknown> | null
    
    // WooCommerce preset
    woocommerce_preset_id: number | null
    
    // Colors
    primary_color: string
    secondary_color: string
    background_color: string
    header_background: string
    header_text_color: string
    user_message_bg: string
    user_message_text: string
    bot_message_bg: string
    bot_message_text: string
    input_bg: string
    input_text: string
    input_border: string
    button_bg: string
    button_text: string
    button_hover_bg: string
    link_color: string
    
    // Typography
    font_family: string
    font_size_base: string
    font_size_header: string
    font_weight_normal: string
    font_weight_bold: string
    line_height: string
    letter_spacing: string
    
    // Bubble
    bubble_icon: string
    bubble_size: string
    bubble_custom_icon: string
    bubble_animation: string
    
    // Window
    window_width: string
    window_height: string
    window_border_radius: string
    window_shadow: string
    
    // Custom CSS
    custom_css: string
    
    // Widget settings (for widget-specific appearance)
    widget_settings?: import('./appearance').WidgetSettings | null
    
    // Appearance overrides
    appearance_overrides: AppearanceOverrides
    
    // Behavior / Personality
    personality_id: number | null
    system_prompt: string
    tone: string
    proactive_engagement: boolean
    proactive_delay_seconds: number
    personality_overrides: PersonalityOverrides
    custom_instructions: string
    rules: string
    forbidden_topics: string
    contact_list_id: number | null
    // Week 28: per-bot output cap (chars). Null means "use global".
    bot_output_char_limit: number | null

    // Week 27.6: BrandCard override (per-bot)
    brand_card_mode?: 'global' | 'override' | null
    brand_card_override?: Record<string, unknown> | null
}

export interface BotResponse {
    success: boolean
    data: {
        bot: Bot
        message?: string
    }
}

export interface BotsListResponse {
    success: boolean
    data: {
        bots: Bot[]
        pagination: {
            total: number
            page: number
            per_page: number
            total_pages: number
        }
    }
}

export interface BotStatsResponse {
    success: boolean
    data: {
        total: number
        active: number
        inactive: number
    }
}

