{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api-evangelist.github.io/granular/json-schema/granular-field-schema.json",
  "title": "Granular Farm Field",
  "description": "JSON Schema for a Granular farm field representing an agricultural parcel with boundary geometry, soil data, and FSA identifiers.",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Unique field identifier"
    },
    "farmId": {
      "type": "string",
      "description": "Parent farm identifier"
    },
    "name": {
      "type": "string",
      "description": "Field name or local identifier"
    },
    "acres": {
      "type": "number",
      "minimum": 0,
      "description": "Field area in acres"
    },
    "boundary": {
      "description": "GeoJSON Feature representing the field boundary polygon",
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["Feature"]
        },
        "geometry": {
          "$ref": "#/$defs/GeoJsonGeometry"
        },
        "properties": {
          "type": "object",
          "additionalProperties": true
        }
      },
      "required": ["type", "geometry"]
    },
    "fsaFarmNumber": {
      "type": "string",
      "description": "USDA Farm Service Agency farm number"
    },
    "fsaTractNumber": {
      "type": "string",
      "description": "USDA FSA tract number"
    },
    "fsaFieldNumber": {
      "type": "string",
      "description": "USDA FSA field number"
    },
    "soilType": {
      "type": "string",
      "description": "Dominant soil taxonomy (e.g., 'Mollisol')"
    },
    "predominantSoil": {
      "type": "string",
      "description": "Dominant soil series name"
    },
    "irrigated": {
      "type": "boolean",
      "description": "Whether the field has irrigation capability"
    },
    "county": {
      "type": "string",
      "description": "County where the field is located"
    },
    "state": {
      "type": "string",
      "description": "US state abbreviation"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": ["id", "farmId", "name"],
  "$defs": {
    "GeoJsonGeometry": {
      "type": "object",
      "description": "GeoJSON geometry object",
      "properties": {
        "type": {
          "type": "string",
          "enum": ["Polygon", "MultiPolygon"]
        },
        "coordinates": {
          "type": "array",
          "description": "Coordinate arrays per GeoJSON specification (RFC 7946)"
        }
      },
      "required": ["type", "coordinates"]
    }
  }
}
