# AppSettings schema endpoint is deprecated.
# Environment manifest endpoint: /api/schema/environment-manifest
# Application Logging Configuration
Logging:
  LogLevel:
    Default: Information
    Microsoft.AspNetCore: Warning

# Serilog Structured Logging Configuration
# Note: Serilog is configured programmatically in Program.cs with environment-adaptive settings.
# This section is provided for reference and potential future configuration-based setup.
#
# Environment-Adaptive Behavior:
# - Development (non-container): Console + File dual output for debugging
# - Production (non-container): File only for persistent logging
# - Container (any environment): Compact JSON Lines to stdout for log aggregation
#
# Container Detection (automatically performed in Program.cs):
# - Primary: Checks for /.dockerenv file (Docker-specific)
# - Fallback: Analyzes /proc/1/cgroup for docker/containerd/kubepods strings
# - Default: Non-container mode if detection fails
#
Serilog:
  # Minimum log level (can be overridden in environment-specific files)
  MinimumLevel: Debug
  # Log level overrides for specific namespaces
  MinimumLevelOverride:
    Microsoft.EntityFrameworkCore: Warning
    Microsoft: Warning
    Orleans: Warning
    System: Warning
    Volo: Warning

# ============================================================================
# Server URL Configuration
# ============================================================================
# Option 1: Kestrel Endpoints (Recommended for production)
# Uncomment and configure Kestrel:Endpoints for production deployments
# This provides full control over HTTPS, certificates, and multiple endpoints.
#
# Kestrel:
#   Endpoints:
#     # HTTP endpoint
#     Http:
#       Url: "http://0.0.0.0:5000"
#
#     # HTTPS endpoint with development certificate
#     Https:
#       Url: "https://0.0.0.0:5001"
#       Certificate:
#         Subject: "localhost"
#         Store: "My"
#         StoreLocation: "LocalMachine"
#         AllowInvalid: true
#
#     # HTTPS endpoint with specific certificate file (pfx)
#     # HttpsPfx:
#     #   Url: "https://example.com:443"
#     #   Certificate:
#     #     Path: "/path/to/certificate.pfx"
#     #     Password: "your-password"
#
#     # IPv6 endpoint example
#     # HttpIPv6:
#     #   Url: "http://[::]:5000"
#
#     # Specific IP binding example
#     # HttpSpecificIP:
#     #   Url: "http://192.168.1.100:5000"

# Option 2: Simple URLs configuration (Fallback)
# Semicolon-separated list of URLs for HTTP and HTTPS endpoints.
# This is simpler but doesn't support certificate configuration.

# Option 3: Environment Variable (Alternative)
# Set ASPNETCORE_URLS environment variable to override configuration.
# Example: ASPNETCORE_URLS="http://0.0.0.0:5000;https://0.0.0.0:5001"

# Configuration Priority:
# 1. Kestrel:Endpoints (highest priority)
# 2. Urls configuration
# 3. ASPNETCORE_URLS environment variable
# 4. Default: http://localhost:5000

# Migration Guide:
# To migrate from Urls to Kestrel:Endpoints:
# 1. Uncomment Kestrel:Endpoints section above
# 2. Copy your URLs from the Urls key to individual endpoint entries
# 3. Add certificate configuration for HTTPS endpoints
# 4. Comment out or remove the Urls key
# ============================================================================

# Allowed hosts for the application
AllowedHosts: "*"

# ============================================================================
# Remote Deployment Configuration Examples
# ============================================================================
# The application now supports remote deployment without address restrictions.
# To enable remote access, use one of the following methods:
#
# 1. Override Urls in appsettings.Production.yml:
#    Urls: "http://0.0.0.0:35167"
#
# 2. Use Kestrel:Endpoints for more control:
#    Kestrel:
#      Endpoints:
#        Http:
#          Url: "http://0.0.0.0:35167"
#
# 3. Use environment variable:
#    export ASPNETCORE_URLS="http://0.0.0.0:35167"
#
# SECURITY RECOMMENDATION:
# In production, use a reverse proxy (Nginx/IIS) in front of this application
# for proper access control, SSL termination, and security hardening.
# Do not expose the application directly to the internet without protection.
# ============================================================================

# Startup Banner Configuration
StartupBanner:
  Enabled: true               # Whether to display the startup banner
  CheckEnvironment: true      # Whether to check environment dependencies
  ShowOrleansInfo: true       # Whether to display Orleans Silo information
  StrictMode: false           # If true, application will not start if required tools are missing

# ============================================================================
# Data Directory Configuration
# ============================================================================
# All application data (SQLite databases, logs, etc.) should be stored
# in a dedicated data directory for easier management and backup.
#
# Default data directory paths:
# - Linux/macOS: ./data or /var/pcode/data
# - Windows: .\data or C:\ProgramData\PCode\data
#
# For Docker deployment, mount this directory to a volume:
#   volumes:
#     - pcode_data:/app/data
#
# For production, consider using environment variable:
#   export DATADIR=/var/pcode/data
#
# This directory is used by all SQLite databases:
# - Main database: {DataDir}/hagicode.db
# - Debug database: {DataDir}/debug.db
# - Orleans storage: {DataDir}/orleans/grains.db
# ============================================================================

# Application Data Directory
# Base directory for all application data files
# Environment variable: DATADIR
DataDir: "./data"

# Database Connection Strings
# For SQLite (default): ConnectionStrings:Default is optional
# - If not set, it will be automatically generated as: {DataDir}/hagicode.db
# - For PostgreSQL, this must be explicitly configured
ConnectionStrings:
  # Default connection string - format depends on Database:Provider
  #
  # For SQLite (default):
  #   Default: "Data Source=./data/hagicode.db"
  #   If omitted, automatically uses: {DataDir}/hagicode.db
  #
  # For PostgreSQL:
  #   Default: "Host=localhost;Port=35439;Database=hagicode;Username=postgres;Password=postgres"
  #   Or use environment variable: ${DATABASE_URL}
  #  Default: "Data Source=./data/hagicode.db"

# ============================================================================
# Database Configuration
# ============================================================================
# HagiCode supports two database providers:
#
# 1. SQLite (Default) - Embedded database, zero configuration
#    - Best for: Single-machine deployments, development, software packages
#    - Pros: No external dependencies, easy setup, portable database file
#    - Cons: Single writer, limited concurrency, not for multi-user teams
#    - Database file: ./data/hagicode.db (auto-created)
#
# 2. PostgreSQL - Production-grade relational database
#    - Best for: Production deployments, multi-user teams, high concurrency
#    - Pros: Multi-writer, high performance, advanced features
#    - Cons: Requires external database installation and configuration
#    - Setup: Configure ConnectionStrings:Default below
#
# To switch to PostgreSQL, set Provider to "postgresql" explicitly:
#   - In appsettings.Production.yml: Provider: "postgresql"
#   - Via environment variable: export Database__Provider=postgresql
# ============================================================================

Database:
  # Database provider: "sqlite" (default) or "postgresql"
  # Environment variable override: Database__Provider
  Provider: "sqlite"

  # Whether to automatically apply database migrations on application startup
  AutoMigrateDatabase: true

  # Whether to automatically run DbUp SQL script migrations on application startup
  AutoRunDbUpMigrations: true

  # Whether to seed data after migration
  AutoSeedData: true

  # Timeout for database operations in seconds
  MigrationTimeoutSeconds: 300

# Orleans Cluster Configuration
Orleans:
  ClusterId: "pcode-cluster"
  ServiceId: "pcode-service"
  # Grain Storage Database Path (SQLite with LINQ to DB)
  # Stored in data directory for easier backup and Docker volume mounting
  # Uses WAL mode for better concurrency
  # If omitted, automatically uses: {DataDir}/orleans/grains.db
  #  GrainStorageDbPath: "Data Source=./data/orleans/grains.db"

# Claude Code Integration Settings
ClaudeCode:
  ExecutablePath: claude
  WorkspacePath: /tmp/claude-workspaces
  TimeoutSeconds: 300
  EnableStreaming: true

# AI Provider Configuration
# Configure CLI-based AI providers with their specific settings
# Note: Supported providers include ClaudeCodeCli, OpenCodeCli, GitHubCopilot, CodebuddyCli, CodexCli
AI:

  # AI Service Settings
  Service:
    # Whether to automatically inject language preference into prompts that don't contain language instructions
    AutoInjectLanguagePreference: true
    # Default language preference when user hasn't set one (null: follow UI, "zh-CN", "en-US")
    DefaultLanguagePreference: "zh-CN"
    # Default executor type used by SessionGrain (ClaudeCodeCli, CodexCli)
    DefaultExecutorType: "ClaudeCodeCli"

  Providers:
    DefaultProvider: "ClaudeCodeCli"  # The default provider to use when none is specified
    Providers:
      # Claude Code CLI Provider (Default)
      ClaudeCodeCli:
        Type: "ClaudeCodeCli"
        ExecutablePath: "claude"  # Path to claude CLI executable
        Model: "claude-3-5-sonnet-20241022"  # Optional: specific model
        WorkingDirectory: null  # Optional: override working directory
        Settings:
          TimeoutSeconds: "3600"  # CLI execution timeout in seconds

      # OpenCode CLI Provider
      OpenCodeCli:
        Type: "OpenCodeCli"
        ExecutablePath: "opencode"  # Path to opencode CLI executable (can be command name or full path)
        Model: "default"  # Model selection (opencode uses its own configuration)
        WorkingDirectory: null  # Optional: override working directory
        Settings:
          TimeoutSeconds: "300"  # CLI execution timeout in seconds
  
      # GitHub Copilot CLI Provider (ACP mode)
      GitHubCopilot:
        Type: "GitHubCopilot"
        Enabled: false  # Set to true to enable GitHub Copilot
        ExecutablePath: "copilot"  # Path to copilot CLI executable
  #      Model: "claude-sonnet-4.5"  # Model: claude-sonnet-4.5, claude-opus-4.5, gpt-5, etc.
        Model: "gpt-4.1"  # Model: claude-sonnet-4.5, claude-opus-4.5, gpt-5, etc.
        WorkingDirectory: null  # Optional: override working directory
        Timeout: 300  # Request timeout in seconds
        StartupTimeout: 30  # Process startup timeout in seconds
        # Permission settings for ACP mode
        Permissions:
          AllowAllTools: false  # Allow all tools (not recommended for production)
          AllowAllPaths: false  # Allow all file system paths (not recommended for production)
          AllowAllUrls: false  # Allow all URL access (not recommended for production)
          AllowedTools: []  # Whitelist of allowed tool names
          AllowedPaths: []  # Whitelist of allowed file system paths
          DeniedTools: []  # Blacklist of denied tool names
          DeniedUrls: []  # Blacklist of denied URLs
        AdditionalArgs: []  # Additional command-line arguments
  
      # Codex CLI Provider (JSON event mode)
      CodexCli:
        Type: "CodexCli"
        Enabled: false
        ExecutablePath: "codex"
        Model: "gpt-5.3-codex"
        WorkingDirectory: null

  # ACP Session Manager Configuration
  SessionManager:
    MaxSessions: 50  # Maximum concurrent sessions (0 for unlimited)
    DefaultWorkingDirectory: null  # Default working directory for sessions

  # Platform Configurations for ACP Session Management
  # Each platform has its own configuration based on its transport type and requirements
  PlatformConfigurations:
    # OpenCode Platform Configuration (stdio-based, no ports needed)
    OpenCodeCli:
      TransportType: "Stdio"  # OpenCode uses stdio for ACP communication
      ExecutablePath: "opencode"  # Path to opencode executable
      Arguments: "acp"  # Command arguments to enable ACP protocol
      StartupTimeoutSec: 5  # Process startup timeout in seconds

    # GitHub Copilot Platform Configuration (stdio-based, no ports needed)
    GitHubCopilot:
      TransportType: "Stdio"  # Copilot uses stdio for ACP communication
      ExecutablePath: "copilot"  # Path to copilot executable
#      Model: "claude-sonnet-4.5"  # Model to use: claude-sonnet-4.5, claude-opus-4.5, gpt-5, etc.
      Model: "gpt-4.1"  # Model to use: claude-sonnet-4.5, claude-opus-4.5, gpt-5, etc.
      StartupTimeoutSec: 30  # Process startup timeout in seconds
      AllowAllTools: false  # Allow all tools (not recommended for production)
      AllowAllPaths: false  # Allow all file system paths (not recommended for production)
      AllowAllUrls: false  # Allow all URL access (not recommended for production)
      AdditionalArgs: []  # Additional command-line arguments (e.g., ["--experimental"])

  # Codex provider settings (non-ACP)
  Codex:
    Enabled: true
    ExecutablePath: "codex"
    Model: "gpt-5.3-codex"
    SandboxMode: "workspace-write"
    WorkingDirectory: null
    SkipGitRepoCheck: true
    ModelReasoningEffort: "high"
    NetworkAccessEnabled: true
    WebSearchMode: null
    WebSearchEnabled: true
    ApprovalPolicy: "never"
    AdditionalDirectories: []
    SessionThreadBindingDatabaseConnectionString: "Data Source=./data/codex.db"
    RequestTimeoutSeconds: 3600
    EnvironmentVariables: {}

# Session Concurrency Settings
SessionConcurrency:
  DefaultMaxConcurrentSessions: 10

# Workspace Persistence Configuration
# Configure where PCode stores temporary workspace files for coding sessions.
# By default, uses the system Temp directory. Uncomment WorkspaceRoot to use a persistent location.
Workspace:
  # WorkspaceRoot: ""  # Optional: Set to a persistent path like "/var/lib/pcode/workspaces" on Linux
                         # If empty or not set, defaults to system Temp directory.
                         # Can be overridden via PCODE_WORKSPACE_ROOT environment variable.
  AutoCreateDirectory: true  # Automatically create the workspace directory if it doesn't exist

# License Service Configuration
License:
  PrimaryServer:
    Endpoint: "https://api.keygen.sh"
    ApiKey: "activ-cc0493de1b3d2d3ab58e3d1115d61564v3"
    AccountId: "0bb7cd41-a70d-4dd2-a740-5e30500cf70b"
    ProductId: "2c73c847-1077-44e6-afeb-651d5e7eb005"
    TimeoutSeconds: 30
  Activation:
    AutoActivateOnStartup: true
    RequireValidLicense: true
  SignatureVerification:
    Enabled: true
    ToleranceSeconds: 300
    StrictMode: true

# Reports Configuration
Reports:
  CacheTtlSeconds: 86400
  EnableCache: true
  EfficiencyWeights:
    SessionWeight: 10
    RoundWeight: 1
    ToolCallWeight: 5
    CodeBlockWeight: 3
    HighActivityMultiplier: 1.2
    MediumActivityMultiplier: 1.0
    LowActivityMultiplier: 0.8
    NormalizationDivisor: 100

# Gamification Configuration
Gamification:
  # Achievement tier thresholds (based on DAILY contribution)
  # Amplified scoring to produce 10000+ range scores
  Tiers:
    BronzeMin: 0
    SilverMin: 1000
    GoldMin: 3000
    DiamondMin: 6000
  # Score weights for positive reinforcement (amplified)
  ScoreWeights:
    SessionWeight: 200
    RoundWeight: 10
    ToolCallWeight: 15
    CodeBlockWeight: 25
    ActiveTimeBonusPer30Min: 50
  # Bonus multipliers for exceptional performance (applied to daily score)
  BonusMultipliers:
    ExceptionalThreshold: 5000
    ExceptionalMultiplier: 1.5
    ExcellentThreshold: 2500
    ExcellentMultiplier: 1.3
    GoodThreshold: 1000
    GoodMultiplier: 1.1
    StandardMultiplier: 1.0
  # Animation settings
  Animation:
    ScoreRevealDuration: 800
    BadgeAnimationDuration: 600
    ProgressRingDuration: 1000
    StaggerDelay: 150
    EnableConfetti: true
    ConfettiThreshold: 6000
    
# Azure Application Insights Configuration
# Provides application performance monitoring, telemetry, and error tracking
# Documentation: https://learn.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview
ApplicationInsights:
  # Whether Application Insights is enabled
  Enable: true
  # Connection string from Azure Portal (Application Insights resource)
  # Can be overridden via APPLICATIONINSIGHTS_CONNECTION_STRING environment variable
  ConnectionString: "InstrumentationKey=4f37a9cf-0fb5-4de4-a6c1-4b9c691215f5;IngestionEndpoint=https://eastasia-0.in.applicationinsights.azure.com/;LiveEndpoint=https://eastasia.livediagnostics.monitor.azure.com/;ApplicationId=cc0fa271-5952-4c71-96d0-540d77449286"

# Version Check Configuration
# Frontend will check for updates and display notifications when available
VersionCheck:
  Enabled: true  # Whether version checking is enabled
  GitHubRepositoryOwner: "HagiCode-org"  # GitHub repository owner
  GitHubRepositoryName: "releases"  # GitHub repository name
  CurrentVersion: null  # Optional: Override auto-detected version (e.g., "v0.1.0")
  HttpTimeoutSeconds: 30  # HTTP timeout for GitHub API requests
  MaxRetries: 3  # Maximum retry attempts for GitHub API requests
  RetryBaseDelayMs: 1000  # Base delay in milliseconds for exponential backoff

# Container First-Run Configuration
# Settings for containerized deployments with auto project discovery
Container:
  MountPath: "/app/workdir"  # Default container mount path for project discovery
  FirstRunCheckEnabled: true  # Enable first-run project discovery flow
  # Environment variable override: HAGICODE_CONTAINER__MOUNTPATH or HAGICODE_CONTAINER__FIRSTRUNCHECKENABLED

# Feedback Configuration
# Settings for user experience feedback collection system
Feedback:
  # User feedback form link
  Link: "https://docs.qq.com/form/page/DRFVGVVp6RFpSRVVR"

  # Whether feedback functionality is enabled
  Enabled: "true"

# RSS Feed Configuration
# Settings for RSS blog feed integration
RssFeed:
  # RSS feed URL to fetch blog posts from
  FeedUrl: "https://docs.hagicode.com/blog/rss.xml"
  # Cache duration in hours for RSS feed content
  CacheDurationHours: 24
  # Maximum number of items to return from the RSS feed
  MaxItems: 5

# Prompts Configuration
# Settings for multilingual prompt file management system
Prompts:
  RootPath: "Resources/Prompts"  # Root path for prompt files (relative to Web project root)
  DefaultLocale: "en-US"  # Default language locale for fallback
  EnableHotReload: false  # Enable runtime hot reload of prompts (requires admin API)
  StrictMode: false  # In strict mode, startup fails if prompt files are missing or invalid
  EnableCache: true  # Enable in-memory caching of prompts
  SupportedLocales:  # List of supported language locales
    - "zh-CN"
    - "en-US"
  # Prompt completeness validation settings
  ValidationMode: "Lenient"  # Validation mode: "Lenient" (warnings only) or "Strict" (throws exception)
  EnableCompletenessValidation: true  # Enable placeholder completeness validation at startup
  TemplateValidationMode: "Strict"  # Template validation mode: "Lenient" or "Strict"

  # Scenario enumeration validation settings
  ValidateAllScenarios: true  # Validate all PromptScenario enum values have corresponding prompt files
  RequiredLocales:  # Required locales for scenario validation
    - "zh-CN"
    - "en-US"

  # Fallback lookup for deprecated filenames (during deprecation period)
  EnableFallbackLookup: true  # Enable fallback lookup for old filename patterns during deprecation

  # Default template engine configuration
  DefaultSyntax: "handlebars"  # Default template syntax: "handlebars" or "scriban"

  # Handlebars template engine configuration
  Handlebars:
    CacheSize: 100  # Maximum number of compiled templates to cache

# Debug Database Configuration
# Stores deserialization error capture data for debugging AI message parsing failures
# If ConnectionString is omitted, automatically uses: {DataDir}/debug.db
DebugDatabase:
  # Enable or disable debug data capture
  Enabled: true

  # Database file location (relative to application root)
  # If omitted or set to default, automatically uses: {DataDir}/debug.db
  ConnectionString: "Data Source=./data/debug.db;"

  # Automatically create schema on startup
  AutoCreateSchema: true

  # How long to keep debug records (in days)
  RetentionDays: 90

  # Maximum database file size before warning (in MB)
  MaxDatabaseSizeMB: 500

  # Write timeout for database operations (in milliseconds)
  WriteTimeout: 5000

  # Query timeout for database operations (in milliseconds)
  QueryTimeout: 30000

  # Maximum concurrent writers
  MaxConcurrentWriters: 10

  # Whether to automatically clean up old records on startup
  AutoCleanup: true
