"""kolaboro_v1 1.0.0: Generated by https://kolaboro.com/open/sdk-gen.py from https://kolaboro.com/api/v1/openapi.json (2026-11-21). Do not edit by hand. MIT licence; data CC BY 4.0, credit Kolaboro.

    from kolaboro_v1 import KolaboroV1
    k = KolaboroV1()
    p = k.get_project(slug="amani-melasti")
"""
import json, urllib.parse, urllib.request
from typing import Any, Dict, List, Optional
try:
    from typing import TypedDict
except ImportError:  # Python < 3.8
    TypedDict = dict

class KolaboroError(Exception):
    def __init__(self, status, body):
        super().__init__("Kolaboro API %s" % status); self.status = status; self.body = body

ListProjectsResponse = TypedDict("ListProjectsResponse", {"api": str, "updated": str, "count": int, "projects": List[Dict[str, Any]]}, total=False)

GetProjectResponse = TypedDict("GetProjectResponse", {"api": str, "license": str, "rules": str, "id": str, "slug": str, "name": str, "developer": Dict[str, Any], "location": Dict[str, Any], "stage": str, "site_status": str, "reviewed": bool, "added": str, "last_checked": str, "published_page": Dict[str, Any], "permit": Dict[str, Any], "handover": Dict[str, Any], "overdue_months": Any, "promises": List[Dict[str, Any]], "published_facts": Dict[str, Any], "published_statements": List[str], "facts_source": str, "change_history": List[Dict[str, Any]], "hourly_findings": List[Dict[str, Any]], "sealed_copy": Dict[str, Any], "register": Any, "public_reports": List[Any], "review": Dict[str, Any], "sources": List[str], "urls": Dict[str, Any]}, total=False)

GetCertificateResponse = TypedDict("GetCertificateResponse", {"certificate": Dict[str, Any], "signature": Dict[str, Any]}, total=False)

ListDevelopersResponse = TypedDict("ListDevelopersResponse", {"api": str, "updated": str, "count": int, "developers": List[Dict[str, Any]]}, total=False)

GetDeveloperResponse = TypedDict("GetDeveloperResponse", {"api": str, "license": str, "rules": str, "slug": str, "id": str, "aliases": List[Any], "names_as_published": List[str], "last_checked": str, "markets": List[str], "projects": List[Dict[str, Any]], "urls": Dict[str, Any]}, total=False)

GetDeveloperWebsiteResponse = TypedDict("GetDeveloperWebsiteResponse", {"api": str, "developer": Dict[str, Any], "updated": str, "legend": Dict[str, Any], "domains": List[Dict[str, Any]]}, total=False)

FindResponse = TypedDict("FindResponse", {"query": str, "count": int, "results": List[Dict[str, Any]]}, total=False)

ListChangesResponse = TypedDict("ListChangesResponse", {"api": str, "licence": str, "sync": str, "since": str, "count": int, "total_after_filter": int, "has_more": bool, "next_cursor": Any, "next": Any, "last_change_at": str, "resume": str, "feed": str, "changes": List[Dict[str, Any]]}, total=False)

ChangesFeedResponse = TypedDict("ChangesFeedResponse", {"version": str, "title": str, "home_page_url": str, "feed_url": str, "description": str, "language": str, "authors": List[Dict[str, Any]], "items": List[Dict[str, Any]]}, total=False)

GetSnapshotsResponse = TypedDict("GetSnapshotsResponse", {"version": str, "file": str, "licence": str, "head_rule": str, "day_rule": str, "copies": str, "note": str, "updated": str, "count": int, "tip": str, "entries": List[Dict[str, Any]], "api": str, "live": Dict[str, Any], "provisional_tip": Dict[str, Any], "chain_tip": str, "verify": Dict[str, Any]}, total=False)

GetDataQualityResponse = TypedDict("GetDataQualityResponse", {"api": str, "computed_at": str, "data_updated": str, "dataset": Dict[str, Any], "build": str, "method": str, "projects": int, "fields": Dict[str, Any], "freshness": Dict[str, Any], "median_days_since_check": int, "median_sources_per_project": int, "markets": List[Dict[str, Any]], "gaps": Dict[str, Any], "validation": Dict[str, Any], "aliases": Dict[str, Any]}, total=False)

GetSlippageResponse = TypedDict("GetSlippageResponse", {"version": str, "computed": str, "month": str, "licence": str, "method": str, "what": str, "rules": Dict[str, Any], "sources": List[str], "fields": List[str], "all": Dict[str, Any], "markets": List[Dict[str, Any]]}, total=False)

GetHandoverHistoryResponse = TypedDict("GetHandoverHistoryResponse", {"id": str, "slug": str, "name": str, "developer": str, "market": str, "stage": str, "current": str, "moves": int, "delay_months": Any, "distinct_dates": int, "events": List[Dict[str, Any]], "developer_page": str, "page": str, "timeline": str, "licence": str, "note": str}, total=False)

GetProvenanceResponse = TypedDict("GetProvenanceResponse", {"attestation": Dict[str, Any], "signature": Dict[str, Any], "history": List[Dict[str, Any]], "history_file": str, "verify": str}, total=False)

ListDeltasResponse = TypedDict("ListDeltasResponse", {"api": str, "page": str, "type": str, "licence": str, "entries": List[Dict[str, Any]], "signature": str, "verify": str}, total=False)

GetDeltaResponse = TypedDict("GetDeltaResponse", {"type": str, "from": Dict[str, Any], "to": Dict[str, Any], "counts": Dict[str, Any], "apply": str, "added": List[Any], "removed": List[Any], "changed": Dict[str, Any]}, total=False)

GetDeltaSignatureResponse = TypedDict("GetDeltaSignatureResponse", {"type": str, "day": str, "file": str, "bytes": int, "sha256": str, "alg": str, "kid": str, "signature": str, "message": str, "public_keys": str}, total=False)

GetTreeHeadResponse = TypedDict("GetTreeHeadResponse", {"tree_head": Dict[str, Any], "signature": Dict[str, Any], "entries": List[Dict[str, Any]], "roots_by_size": List[str], "rules": Dict[str, Any]}, total=False)

GetInclusionProofResponse = TypedDict("GetInclusionProofResponse", {"type": str, "project": str, "day": str, "record": Dict[str, Any], "leaf": str, "leaf_index": int, "day_size": int, "day_root": str, "day_path": List[str], "snapshot": Dict[str, Any], "day_index": int, "log_path": List[str], "tree_head": Dict[str, Any], "signature": Dict[str, Any], "verify": str}, total=False)

GetConsistencyProofResponse = TypedDict("GetConsistencyProofResponse", {"type": str, "first": int, "second": int, "first_root": str, "second_root": str, "path": List[str], "tree_head": Dict[str, Any], "signature": Dict[str, Any], "verify": str}, total=False)

GetMarketChartResponse = TypedDict("GetMarketChartResponse", {"market": str, "country": str, "disclosure": Dict[str, Any], "delays": Dict[str, Any], "as_of": Dict[str, Any], "page": str, "licence": str, "svg": Dict[str, Any], "link": Dict[str, Any]}, total=False)

GetMonitoringResponse = TypedDict("GetMonitoringResponse", {"about": str, "per_page": List[Dict[str, Any]], "per_day": List[Dict[str, Any]], "samples": List[Dict[str, Any]], "edge_now": Dict[str, Any]}, total=False)


class KolaboroV1:
    """Client for https://kolaboro.com/api/v1 (no key). Keeps ETags and answers 304s from its cache."""
    def __init__(self, base: str = "https://kolaboro.com", timeout: float = 60):
        self.base = base.rstrip("/"); self.timeout = timeout; self.last = None; self._etag = {}
    def _get(self, path, query):
        q = urllib.parse.urlencode({k: v for k, v in query.items() if v is not None})
        url = self.base + path + ("?" + q if q else ""); h = {"user-agent": "kolaboro-v1-python/1.0.0"}
        if url in self._etag: h["if-none-match"] = self._etag[url][0]
        try:
            with urllib.request.urlopen(urllib.request.Request(url, headers=h), timeout=self.timeout) as r:
                body = r.read(); data = json.loads(body)
                self.last = {"url": url, "status": r.status, "signature": r.headers.get("x-kolaboro-signature"), "key_id": r.headers.get("x-kolaboro-key-id"), "body": body}
                if r.headers.get("etag"): self._etag[url] = (r.headers.get("etag"), data)
                return data
        except urllib.error.HTTPError as e:
            if e.code == 304 and url in self._etag: self.last = {"url": url, "status": 304, "cached": True}; return self._etag[url][1]
            raise KolaboroError(e.code, e.read()[:500])

    def list_projects(self) -> "ListProjectsResponse":
        """Every named project with its key facts (stable slug and id)."""
        return self._get(f"/api/v1/projects", {})

    def get_project(self, slug: str) -> "GetProjectResponse":
        """One named project: facts, sources, checks, dates."""
        return self._get(f"/api/v1/projects/{urllib.parse.quote(str(slug), safe='')}", {})

    def get_certificate(self, slug: str) -> "GetCertificateResponse":
        """Verification certificate: canonical facts, their SHA-256 and the Ed25519 signature."""
        return self._get(f"/api/v1/projects/{urllib.parse.quote(str(slug), safe='')}/certificate", {})

    def list_developers(self) -> "ListDevelopersResponse":
        """Every developer with its projects."""
        return self._get(f"/api/v1/developers", {})

    def get_developer(self, slug: str) -> "GetDeveloperResponse":
        """One developer and its projects."""
        return self._get(f"/api/v1/developers/{urllib.parse.quote(str(slug), safe='')}", {})

    def get_developer_website(self, slug: str) -> "GetDeveloperWebsiteResponse":
        """Website forensics of a developer: reachability, TLS, domain registration."""
        return self._get(f"/api/v1/developers/{urllib.parse.quote(str(slug), safe='')}/website", {})

    def find(self, q: str, lang: Optional[str] = None) -> "FindResponse":
        """Free-text search in 8 languages over project names, developers and places."""
        return self._get(f"/api/v1/find", {'q': q, 'lang': lang})

    def list_changes(self, since: Optional[str] = None) -> "ListChangesResponse":
        """Changes since a date, for incremental sync."""
        return self._get(f"/api/v1/changes", {'since': since})

    def changes_feed(self) -> "ChangesFeedResponse":
        """The same changes as a JSON Feed 1.1."""
        return self._get(f"/api/v1/changes/feed.json", {})

    def get_snapshots(self) -> "GetSnapshotsResponse":
        """The daily snapshot hash chain of /data/named.json."""
        return self._get(f"/api/v1/snapshots", {})

    def get_data_quality(self) -> "GetDataQualityResponse":
        """Coverage and freshness of every field, by market."""
        return self._get(f"/api/v1/data-quality", {})

    def get_slippage(self) -> "GetSlippageResponse":
        """Handover slippage statistics per market (historical, with sample sizes)."""
        return self._get(f"/api/v1/slippage", {})

    def get_handover_history(self, slug: str) -> "GetHandoverHistoryResponse":
        """Every handover date on record for a project, with sources."""
        return self._get(f"/api/v1/handover-history/{urllib.parse.quote(str(slug), safe='')}", {})

    def get_provenance(self) -> "GetProvenanceResponse":
        """Signed build attestation: commit, dataset hash, worker tree."""
        return self._get(f"/api/v1/provenance", {})

    def list_deltas(self) -> "ListDeltasResponse":
        """Index of the signed daily delta files."""
        return self._get(f"/api/v1/delta", {})

    def get_delta(self, day: str) -> "GetDeltaResponse":
        """One daily delta file (exact bytes, signed in x-kolaboro-signature)."""
        return self._get(f"/api/v1/delta/{urllib.parse.quote(str(day), safe='')}", {})

    def get_delta_signature(self, day: str) -> "GetDeltaSignatureResponse":
        """The Ed25519 signature of one delta file as JSON."""
        return self._get(f"/api/v1/delta/{urllib.parse.quote(str(day), safe='')}.sig", {})

    def get_tree_head(self) -> "GetTreeHeadResponse":
        """Signed tree head and entries of the transparency log."""
        return self._get(f"/api/v1/tlog", {})

    def get_inclusion_proof(self, project: str, day: Optional[str] = None) -> "GetInclusionProofResponse":
        """Merkle inclusion proof of one project record."""
        return self._get(f"/api/v1/tlog/proof", {'project': project, 'day': day})

    def get_consistency_proof(self, first: int, second: Optional[int] = None) -> "GetConsistencyProofResponse":
        """Merkle consistency proof between two log sizes (append-only)."""
        return self._get(f"/api/v1/tlog/consistency", {'first': first, 'second': second})

    def get_market_chart(self, market: str, lang: Optional[str] = None) -> "GetMarketChartResponse":
        """Delay and disclosure figures of a market, with ready SVG charts."""
        return self._get(f"/api/v1/charts/{urllib.parse.quote(str(market), safe='')}", {'lang': lang})

    def get_monitoring(self) -> "GetMonitoringResponse":
        """Synthetic monitoring of the 20 key pages, 30 days."""
        return self._get(f"/api/v1/monitoring", {})

