"""Project-wide information hub — single source of truth for all audiences.

Consumed by: GUI about panel, CLI `oas info`, API `/api/info`.
"""

from __future__ import annotations

from typing import Any, Dict, List

from oasyce import __version__

# ── Version & identity ────────────────────────────────────────────
PROJECT_NAME = "Oasyce"
VERSION = __version__
TAGLINE_EN = "Data-rights clearing network for the machine economy"
TAGLINE_ZH = "面向机器经济的数据权利清算网络"
LICENSE = "MIT"

# ── Links ─────────────────────────────────────────────────────────
LINKS = {
    "homepage": "https://oasyce.com",
    "github_project": "https://github.com/Shangri-la-0428/Oasyce_Project",
    "github_engine": "https://github.com/Shangri-la-0428/oasyce-net",
    "whitepaper": "https://github.com/Shangri-la-0428/Oasyce_Project/blob/main/docs/WHITEPAPER.md",
    "protocol_overview": "https://github.com/Shangri-la-0428/Oasyce_Project/blob/main/docs/PROTOCOL_OVERVIEW.md",
    "discord": "https://discord.gg/oasyce",
    "email": "wutc@oasyce.com",
}

# ── Audience-targeted sections ────────────────────────────────────

QUICK_START: Dict[str, str] = {
    "en": (
        "1. pip install oasyce\n"
        "2. oas bootstrap          # self-update + wallet + DataVault readiness\n"
        "3. oas demo               # run register -> quote -> buy once\n"
        "4. oas start              # launch node + dashboard\n"
        "5. Optional: oas doctor   # diagnostics"
    ),
    "zh": (
        "1. pip install oasyce\n"
        "2. oas bootstrap          # 自更新 + 钱包 + DataVault 就绪\n"
        "3. oas demo               # 先跑一遍注册 -> 报价 -> 购买\n"
        "4. oas start              # 启动节点 + 仪表盘\n"
        "5. 可选: oas doctor       # 诊断环境"
    ),
}

HOW_IT_WORKS: Dict[str, str] = {
    "en": (
        "Oasyce is a decentralized protocol where AI agents autonomously "
        "register, discover, license, and settle data rights. "
        "Data owners register files and receive a cryptographic proof-of-provenance certificate (PoPc). "
        "AI agents discover data via a Recall-Rank pipeline, negotiate prices through bonding curves, "
        "and settle transactions with escrow-protected OAS tokens. "
        "All interactions are recorded on a peer-to-peer ledger with Ed25519 signatures."
    ),
    "zh": (
        "Oasyce 是一个去中心化协议，AI 代理在其中自主注册、发现、许可和结算数据权利。"
        "数据所有者注册文件并获得加密来源证明证书 (PoPc)。"
        "AI 代理通过 Recall-Rank 管道发现数据，通过联合曲线协商价格，"
        "并使用托管保护的 OAS 代币进行结算。"
        "所有交互都记录在使用 Ed25519 签名的点对点账本上。"
    ),
}

ARCHITECTURE: Dict[str, str] = {
    "en": (
        "Core Layers:\n"
        "  - Schema Registry: Unified validation for data/capability/oracle/identity assets\n"
        "  - Engine Pipeline: Scan -> Classify -> Metadata -> PoPc Certificate -> Register\n"
        "  - Discovery: Recall (broad retrieval) -> Rank (trust + economics) with feedback loop\n"
        "  - Settlement: Bonding curve pricing, escrow, share distribution\n"
        "  - Access Control: L0 (metadata) / L1 (sample) / L2 (compute) / L3 (full)\n"
        "  - P2P Network: Ed25519 identity, gossip sync, PoS consensus\n"
        "  - Risk Engine: Auto-classification (public/internal/sensitive)"
    ),
    "zh": (
        "核心层级:\n"
        "  - Schema Registry: 统一验证 data/capability/oracle/identity 四种资产类型\n"
        "  - 引擎管道: 扫描 -> 分类 -> 元数据 -> PoPc 证书 -> 注册\n"
        "  - 发现引擎: Recall (广召回) -> Rank (信任 + 经济) + 反馈循环\n"
        "  - 结算引擎: 联合曲线定价、托管、份额分配\n"
        "  - 访问控制: L0 (元数据) / L1 (采样) / L2 (计算) / L3 (完整)\n"
        "  - P2P 网络: Ed25519 身份、gossip 同步、PoS 共识\n"
        "  - 风险引擎: 自动分级 (public/internal/sensitive)"
    ),
}

ECONOMICS: Dict[str, str] = {
    "en": (
        "Token: OAS\n"
        "Pricing: Bonding curve (reserve ratio 0.35) — more buyers = higher price, no order book\n"
        "Shares: Early buyers earn more (diminishing: 100% -> 80% -> 60% -> 40%)\n"
        "Rights multiplier: original 1.0x / co_creation 0.9x / licensed 0.7x / collection 0.3x\n"
        "Staking: Validators stake OAS to produce blocks and earn rewards\n"
        "Block reward: 4.0 OAS (mainnet), halving every ~1M blocks\n"
        "Escrow: Funds locked before execution, released after quality verification\n"
        "Reputation: Long-term score — bad behavior follows you"
    ),
    "zh": (
        "代币: OAS\n"
        "定价: 联合曲线 (储备率 0.35) — 买家越多价格越高，无订单簿\n"
        "份额: 早期买家获利更多 (递减: 100% -> 80% -> 60% -> 40%)\n"
        "权利系数: 原创 1.0x / 共创 0.9x / 授权 0.7x / 收藏 0.3x\n"
        "质押: 验证者质押 OAS 出块并获得奖励\n"
        "区块奖励: 4.0 OAS (主网)，每约 100 万块减半\n"
        "托管: 执行前锁定资金，质量验证后释放\n"
        "声誉: 长期评分 — 不良行为如影随形"
    ),
}

UPDATE_GUIDE: Dict[str, str] = {
    "en": (
        "Update:\n"
        "  oas update\n"
        "  # or: python -m pip install --upgrade --upgrade-strategy eager oasyce odv\n"
        "\n"
        "AI-first bootstrap:\n"
        "  oas bootstrap\n"
        "\n"
        "Build from source:\n"
        "  git clone https://github.com/Shangri-la-0428/oasyce-net\n"
        "  cd oasyce-net\n"
        "  pip install -e .\n"
        "\n"
        "Run tests:\n"
        "  python -m pytest tests/ -v\n"
        "\n"
        "Contribute:\n"
        "  Fork -> Branch -> PR. See CONTRIBUTING.md for details."
    ),
    "zh": (
        "更新:\n"
        "  oas update\n"
        "  # 或: python -m pip install --upgrade --upgrade-strategy eager oasyce odv\n"
        "\n"
        "AI-first 启动:\n"
        "  oas bootstrap\n"
        "\n"
        "从源码构建:\n"
        "  git clone https://github.com/Shangri-la-0428/oasyce-net\n"
        "  cd oasyce-net\n"
        "  pip install -e .\n"
        "\n"
        "运行测试:\n"
        "  python -m pytest tests/ -v\n"
        "\n"
        "贡献:\n"
        "  Fork -> Branch -> PR。详见 CONTRIBUTING.md。"
    ),
}

BETA_ONBOARDING: Dict[str, str] = {
    "en": (
        "Beta Onboarding:\n"
        "  - This beta is AI-first. The long-term user is an agent; the dashboard is a temporary collaboration surface.\n"
        "  - Before real work, run `oas bootstrap` so the agent upgrades Oasyce + DataVault, ensures a wallet exists, and turns this machine into a managed install.\n"
        "  - First safe path: register one asset -> quote it -> buy it once with an Idempotency-Key -> verify holdings.\n"
        "  - Success means: the action returns a trace_id, the status is machine-readable, and the result can be verified from holdings or transactions.\n"
        "  - If buy times out, do not submit a second financial action blindly. Reuse the same Idempotency-Key or inspect support data first.\n"
        "  - Before inviting a new beta user, run the beta smoke checklist and confirm the core flow still passes locally."
    ),
    "zh": (
        "公测引导:\n"
        "  - 这次公测是 AI-first。长期用户是 agent，dashboard 只是临时的人机协作界面。\n"
        "  - 真正开始使用前，先跑 `oas bootstrap`，让 agent 自动升级 Oasyce + DataVault、确保钱包已就绪，并把这台机器切成 managed install。\n"
        "  - 第一条安全主路径: 注册一个资产 -> 请求报价 -> 用 Idempotency-Key 买一次 -> 校验持仓。\n"
        "  - 成功的定义: 返回 trace_id，状态可被机器判定，并且能从持仓或交易记录验证结果。\n"
        "  - 如果 buy 超时，不要盲目再次发起第二笔金融动作。复用同一个 Idempotency-Key，或先查看 support 数据。\n"
        "  - 在邀请新的 beta 用户前，先跑 beta smoke checklist，确认核心流程仍然本地通过。"
    ),
}


def get_info(lang: str = "en") -> Dict[str, Any]:
    """Return full project info dict, suitable for JSON serialization."""
    l = lang if lang in ("en", "zh") else "en"
    return {
        "project": PROJECT_NAME,
        "version": VERSION,
        "tagline": TAGLINE_EN if l == "en" else TAGLINE_ZH,
        "license": LICENSE,
        "links": LINKS,
        "asset_types": ["data", "capability", "oracle", "identity"],
        "schema_version": 1,
        "quick_start": QUICK_START[l],
        "how_it_works": HOW_IT_WORKS[l],
        "architecture": ARCHITECTURE[l],
        "economics": ECONOMICS[l],
        "update_guide": UPDATE_GUIDE[l],
        "beta_onboarding": BETA_ONBOARDING[l],
    }
