from __future__ import annotations

from typing import Any

from auto_test_domains.base import build_domain_report, run_pipeline_round


COMPANY_ID = "a1d69bf1-b95e-4832-9258-5bc35c629e9a"


def run_case(config: dict[str, Any], report_root) -> dict[str, Any]:
    """
    company domain 回归。

    company 当前只有读取与绑定语义，不支持 create/update/delete。
    这里至少验证：
    1. `GET /company/list` 可正常加载
    2. 本地公司记录可与远端建立绑定
    3. 关键字段在远端确实存在
    """

    dataset_root = f"{config['project_root']}/tests/fixtures/auto_sync/datasource/company"
    common_root = f"{config['project_root']}/tests/fixtures/auto_sync/datasource/common_baseline"

    round_1 = run_pipeline_round(
        config=config,
        dataset_dir=f"{dataset_root}/round_1_bind",
        previous_dataset_dir=None,
        base_dataset_dir=common_root,
        base_dataset_files=["company_1.jsonl"],
        domain_name="company",
        round_name="round_1_bind",
        purpose="加载公司列表并验证 company 绑定链路",
        required_bindings={
            "company": [COMPANY_ID],
        },
        expected_binding_pairs={
            "company": {COMPANY_ID: COMPANY_ID},
        },
        expected_bound_fields={
            "remote": {
                "company": {
                    COMPANY_ID: {
                        "name": "金上公司",
                        "code": "028B",
                    }
                }
            }
        },
        coverage={
            "api": ["GET /company/list"],
            "notes": "company 为只读域，本用例显式验证远端加载、自动绑定与关键字段校验，不短路通过。",
        },
    )

    return build_domain_report(
        domain="company",
        description="公司 domain 的只读回归测试。验证 company 列表加载、绑定与基础字段对齐。",
        rounds=[round_1],
    )