from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def main():
    required = [
        "README.md",
        "docker-compose.yml",
        "ontology/global-shipment.ttl",
        "data/qingdao-export-sample.ttl",
        "queries/order-status.rq",
        "queries/risk-orders.rq",
        "queries/supplier-product-quotes.rq",
        "queries/product-performance.rq",
        "queries/ai-market-recommended-prices.rq",
        "queries/supplier-share-governance.rq",
        "app/main.py",
    ]
    for path in required:
        if not (ROOT / path).exists():
            raise SystemExit(f"缺少文件: {path}")

    ontology = (ROOT / "ontology/global-shipment.ttl").read_text(encoding="utf-8")
    sample = (ROOT / "data/qingdao-export-sample.ttl").read_text(encoding="utf-8")

    required_terms = [
        "gesli:GlobalShipmentOntology",
        "gesli:ServiceBrand",
        "gesli:ServiceProduct",
        "gesli:ProductPerformanceProfile",
        "gesli:SupplierProductOffering",
        "gesli:ScheduledServiceInstance",
        "gesli:SolutionPlan",
        "gesli:AIRecommendedPrice",
        "gesli:SupplierShareGovernanceStrategy",
    ]
    for term in required_terms:
        if term not in ontology:
            raise SystemExit(f"本体缺少核心定义: {term}")

    count = sample.count("a gesli:QingdaoExportOrder")
    if count < 2:
        raise SystemExit("样本订单不足。")

    offering_count = sample.count("a gesli:SupplierProductOffering")
    if offering_count < 5:
        raise SystemExit("供应商产品关系样本不足。")

    if "sample:Maersk a gesli:Carrier" in sample:
        raise SystemExit("马士基品牌仍被错误建模为平台供应商。")

    print(
        f"基础检查通过。当前有 {count} 票青岛出口样本订单，"
        f"{offering_count} 条供应商产品关系。"
    )


if __name__ == "__main__":
    main()
