# Info: KCL Radicle task schemas for provisioning (Provisioning)
# Author: Provisioning System
# Release: 0.0.1
# Date: 2025-07-24

import regex

schema User:
    """
    User settings for Radicle
    """
    name: str
    group: str = name
    home?: str = "/home/${name}"

schema RadicleNode:
    """
    Radicle Node configuration
    """
    name: str = "radicle"
    version: str
    run_user: User = {
        name = "radicle"
    }
    work_path: str = "/var/lib/radicle"
    config_path: str = "/etc/radicle"
    run_path: str = "/usr/local/bin/rad"
    bind_addr: str = "0.0.0.0"
    bind_port: int = 8776
    peer_port: int = 8777
    web_ui_port: int = 8080
    storage_path: str = "/var/lib/radicle/storage"
    seeds: [str] = []
    external_addresses: [str] = []
    connect_timeout: int = 10
    announce: bool = True
    log_level: "trace" | "debug" | "info" | "warn" | "error" = "info"
    
    check:
        1 <= bind_port <= 65535, "bind_port must be between 1 and 65535, inclusive"
        1 <= peer_port <= 65535, "peer_port must be between 1 and 65535, inclusive"
        1 <= web_ui_port <= 65535, "web_ui_port must be between 1 and 65535, inclusive"
        len(run_user.name) > 0, "Check run_user name"
        len(work_path) > 0, "Check work_path"
        len(storage_path) > 0, "Check storage_path"
        connect_timeout > 0, "connect_timeout must be positive"

schema RadicleHttpd:
    """
    Radicle HTTP daemon configuration
    """
    enabled: bool = True
    bind_addr: str = "0.0.0.0"
    bind_port: int = 8080
    assets_path?: str
    
    check:
        1 <= bind_port <= 65535, "bind_port must be between 1 and 65535, inclusive"