{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usetrackly-app/json-schema/usetrackly-app-company-search-schema.json",
  "title": "CompanySearch",
  "description": "Response envelope for `/api/v1/companies/search`.",
  "x-generated": "2026-11-27",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usetrackly-app-openapi.json#/components/schemas/CompanySearch",
  "type": "object",
  "required": [
    "success",
    "companies",
    "similarCompanies",
    "count",
    "total",
    "searchSource",
    "resolution",
    "servedFromCache",
    "dataFreshnessMs"
  ],
  "properties": {
    "success": {
      "type": "boolean",
      "const": true
    },
    "companies": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/CompanyDetailed"
      }
    },
    "similarCompanies": {
      "type": "array",
      "description": "Optional partial-name candidates, kept separate from resolved matches.",
      "items": {
        "$ref": "#/$defs/CompanyDetailed"
      }
    },
    "count": {
      "type": "integer"
    },
    "total": {
      "type": "integer"
    },
    "similarTotal": {
      "type": "integer",
      "description": "Total optional similar companies before pagination."
    },
    "searchSource": {
      "type": "string",
      "enum": [
        "sql_fallback",
        "azure_semantic"
      ],
      "description": "Backward-compatible retrieval label. Use resolution.engine for deterministic search metadata."
    },
    "resolution": {
      "type": "object",
      "required": [
        "kind",
        "engine",
        "strategy",
        "confidence"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "exact",
            "corrected",
            "missing"
          ]
        },
        "engine": {
          "type": "string",
          "enum": [
            "deterministic_sql"
          ]
        },
        "strategy": {
          "type": "string",
          "enum": [
            "name",
            "domain",
            "alias",
            "correction",
            "none"
          ]
        },
        "confidence": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1
        }
      }
    },
    "request": {
      "type": "object",
      "description": "Present only when `resolution.kind` is `missing`.",
      "required": [
        "available",
        "companyName",
        "endpoint"
      ],
      "properties": {
        "available": {
          "type": "boolean",
          "const": true
        },
        "companyName": {
          "type": "string",
          "maxLength": 160
        },
        "endpoint": {
          "type": "string",
          "const": "/api/jobscout/companies/request"
        }
      }
    },
    "servedFromCache": {
      "type": "boolean"
    },
    "dataFreshnessMs": {
      "type": "integer"
    }
  },
  "$defs": {
    "CompanyDetailed": {
      "type": "object",
      "description": "Full company record returned by `/api/v1/companies` and `/api/v1/companies/search`.",
      "required": [
        "id",
        "name",
        "domain",
        "isFavorite",
        "pmJobCount",
        "totalJobCount",
        "mbaJobCount",
        "functionCounts"
      ],
      "properties": {
        "id": {
          "type": "integer"
        },
        "name": {
          "type": "string"
        },
        "domain": {
          "type": "string"
        },
        "logoUrl": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri"
        },
        "atsType": {
          "type": [
            "string",
            "null"
          ],
          "description": "ATS vendor slug (e.g. greenhouse, lever, ashby, eightfold)."
        },
        "industry": {
          "type": [
            "string",
            "null"
          ]
        },
        "isFavorite": {
          "type": "boolean"
        },
        "pmJobCount": {
          "type": "integer",
          "description": "Number of PM-classified roles currently active at this company."
        },
        "totalJobCount": {
          "type": "integer",
          "description": "Total active roles at this company (post-filter)."
        },
        "mbaJobCount": {
          "type": "integer",
          "description": "Active MBA-level roles at this company."
        },
        "functionCounts": {
          "type": "object",
          "description": "Map of `JobFunction` value to active role count at this company.",
          "additionalProperties": {
            "type": "integer"
          }
        },
        "companyStage": {
          "type": [
            "string",
            "null"
          ]
        },
        "fundingStage": {
          "type": [
            "string",
            "null"
          ]
        },
        "fundingSeries": {
          "type": [
            "string",
            "null"
          ]
        },
        "valuationMillions": {
          "type": [
            "number",
            "null"
          ]
        },
        "lastFinancingDate": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "description": {
          "type": [
            "string",
            "null"
          ]
        },
        "ycBatch": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    }
  }
}