{
  "$defs": {
    "CompetitorEntry": {
      "description": "One competitor in the deal.",
      "properties": {
        "incumbent": {
          "description": "Whether they're the incumbent.",
          "type": "boolean"
        },
        "name": {
          "type": "string"
        },
        "notes": {
          "description": "Free-form notes (positioning vs them).",
          "type": [
            "string",
            "null"
          ]
        }
      },
      "required": [
        "name",
        "incumbent"
      ],
      "type": "object"
    },
    "IsoCurrency": {
      "description": "ISO 4217 currency code.",
      "pattern": "^[A-Z]{3}$",
      "type": "string"
    },
    "IsoDate": {
      "description": "ISO 8601 date (YYYY-MM-DD).",
      "format": "date",
      "type": "string"
    },
    "LossReason": {
      "description": "Loss-reason taxonomy (for closed-lost analysis).",
      "oneOf": [
        {
          "enum": [
            "price",
            "timing",
            "other"
          ],
          "type": "string"
        },
        {
          "const": "competitor",
          "description": "Lost to a named competitor.",
          "type": "string"
        },
        {
          "const": "no_budget",
          "description": "No budget allocated.",
          "type": "string"
        },
        {
          "const": "product_fit",
          "description": "Product gap.",
          "type": "string"
        },
        {
          "const": "no_champion",
          "description": "No clear pain / business case.",
          "type": "string"
        },
        {
          "const": "account_change",
          "description": "Reorganisation / personnel change killed it.",
          "type": "string"
        },
        {
          "const": "no_decision",
          "description": "No-decision / status quo wins.",
          "type": "string"
        }
      ]
    },
    "OpportunitySource": {
      "description": "Source / inbound channel.",
      "oneOf": [
        {
          "enum": [
            "inbound",
            "outbound_cold",
            "referral",
            "partner",
            "event",
            "renewal",
            "other"
          ],
          "type": "string"
        },
        {
          "const": "expansion",
          "description": "Existing customer expansion.",
          "type": "string"
        }
      ]
    },
    "OpportunityStage": {
      "description": "Pipeline stage.",
      "oneOf": [
        {
          "enum": [
            "closed_won",
            "closed_lost"
          ],
          "type": "string"
        },
        {
          "const": "lead",
          "description": "Lead / inbound, not yet qualified.",
          "type": "string"
        },
        {
          "const": "qualifying",
          "description": "Initial qualification (BANT / MEDDPICC opening).",
          "type": "string"
        },
        {
          "const": "discovery",
          "description": "Discovery — pain + decision process mapped.",
          "type": "string"
        },
        {
          "const": "demo",
          "description": "Demo / evaluation.",
          "type": "string"
        },
        {
          "const": "proposal",
          "description": "Proposal / commercial terms shared.",
          "type": "string"
        },
        {
          "const": "negotiation",
          "description": "Active negotiation / paper process.",
          "type": "string"
        },
        {
          "const": "commit",
          "description": "Verbal / commit.",
          "type": "string"
        },
        {
          "const": "disqualified",
          "description": "Disqualified before close.",
          "type": "string"
        }
      ]
    },
    "PathRef": {
      "description": "Path-based cross-reference relative to .corpospec/ root.\nPattern: `^[a-z0-9_-]+(/[a-z0-9_.-]+)+$`",
      "pattern": "^[a-z0-9_-]+(/[a-z0-9_.-]+)+$",
      "type": "string"
    }
  },
  "$id": "https://corpospec.com/schemas/v0.16.0/opportunity.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "Sales opportunity.",
  "properties": {
    "account": {
      "$ref": "#/$defs/PathRef",
      "description": "PathRef to the customer / prospect (customer.rs)."
    },
    "activity_refs": {
      "description": "PathRefs to associated activities (calls, demos, emails).",
      "items": {
        "$ref": "#/$defs/PathRef"
      },
      "type": "array"
    },
    "amount": {
      "format": "double",
      "type": "number"
    },
    "close_date": {
      "$ref": "#/$defs/IsoDate",
      "description": "Target close date."
    },
    "closed_at": {
      "anyOf": [
        {
          "$ref": "#/$defs/IsoDate"
        },
        {
          "type": "null"
        }
      ]
    },
    "competitors": {
      "items": {
        "$ref": "#/$defs/CompetitorEntry"
      },
      "type": "array"
    },
    "created_at": {
      "$ref": "#/$defs/IsoDate"
    },
    "currency": {
      "$ref": "#/$defs/IsoCurrency",
      "description": "Deal currency + amount (annual contract value)."
    },
    "id": {
      "$ref": "#/$defs/PathRef"
    },
    "loss_detail": {
      "description": "Free-form lost narrative.",
      "type": [
        "string",
        "null"
      ]
    },
    "loss_reason": {
      "anyOf": [
        {
          "$ref": "#/$defs/LossReason"
        },
        {
          "type": "null"
        }
      ],
      "description": "Closed-lost reason (only set when stage == ClosedLost)."
    },
    "name": {
      "type": "string"
    },
    "owner": {
      "$ref": "#/$defs/PathRef"
    },
    "probability": {
      "description": "Win probability (0.0–1.0).",
      "format": "double",
      "type": "number"
    },
    "proposed_plan_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/PathRef"
        },
        {
          "type": "null"
        }
      ],
      "description": "PathRef to the proposed pricing plan."
    },
    "source": {
      "$ref": "#/$defs/OpportunitySource"
    },
    "stage": {
      "$ref": "#/$defs/OpportunityStage"
    }
  },
  "required": [
    "id",
    "account",
    "name",
    "stage",
    "source",
    "owner",
    "currency",
    "amount",
    "probability",
    "close_date",
    "competitors",
    "created_at"
  ],
  "title": "Opportunity",
  "type": "object",
  "x-corpospec-pillar": "market"
}