{
  "id": "gitea-client",
  "title": "Gitea API Client",
  "type": "library",
  "tier": "starlark",
  "version": "1.0.1",
  "description": "Shared Gitea client — connections, API helpers, optional data caching.",
  "author": "switchboard",

  "permissions": ["api.http", "connections.read", "db.read", "db.write"],

  "exports": [
    "get_repos", "get_issues", "get_issue", "create_issue",
    "update_issue", "add_comment", "get_prs", "get_ci_status"
  ],

  "api_routes": [
    {"method": "GET",  "path": "/repos"},
    {"method": "GET",  "path": "/issues"},
    {"method": "GET",  "path": "/issues/*"},
    {"method": "POST", "path": "/issues"},
    {"method": "GET",  "path": "/prs"},
    {"method": "GET",  "path": "/ci/*"},
    {"method": "POST", "path": "/sync"}
  ],

  "connections": [
    {
      "type": "gitea",
      "label": "Gitea Instance",
      "fields": {
        "base_url":  {"type": "url",    "required": "true",  "label": "Server URL"},
        "api_token": {"type": "secret", "required": "true",  "label": "API Token"},
        "org":       {"type": "string", "required": "false", "label": "Default Org"}
      },
      "scopes": ["global", "team", "personal"]
    }
  ],

  "db_tables": {
    "repos": {
      "columns": {
        "connection_id": "text",
        "full_name": "text",
        "owner": "text",
        "name": "text",
        "description": "text",
        "html_url": "text",
        "open_issues": "integer",
        "synced_at": "timestamp"
      },
      "indexes": [["connection_id"]]
    },
    "issues": {
      "columns": {
        "connection_id": "text",
        "repo_full_name": "text",
        "number": "integer",
        "title": "text",
        "state": "text",
        "labels": "text",
        "assignee": "text",
        "body": "text",
        "created_at": "text",
        "synced_at": "timestamp"
      },
      "indexes": [["connection_id", "repo_full_name"]]
    }
  },

  "schema_version": 1
}
