{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nauticopen.org/schema/0.1/feed.schema.json",
  "title": "Nautic Open Feed",
  "description": "A feed of bookable nautical resources published by a single provider.",
  "type": "object",
  "required": ["schema", "provider", "resources"],
  "properties": {
    "schema": {
      "type": "string",
      "const": "https://nauticopen.org/schema/0.1",
      "description": "Namespace identifying which version of Nautic Open this feed uses."
    },
    "provider": { "$ref": "#/$defs/provider" },
    "resources": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/resource" }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "provider": {
      "type": "object",
      "description": "The organization publishing this feed (schema.org Organization equivalent).",
      "required": ["id", "type", "name"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stable identifier for the provider, unique within the publisher's own namespace."
        },
        "type": {
          "type": "string",
          "const": "Organization"
        },
        "name": { "type": "string", "minLength": 1 },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Informational URL for the provider (e.g. its website)."
        },
        "email": { "type": "string", "format": "email" },
        "description": { "type": "string" }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": {}
      }
    },
    "resource": {
      "type": "object",
      "description": "Something a provider offers: a boat, a course, a trip, an event, a service. A resource must publish EITHER 'offers' OR 'schedule', never both.",
      "required": ["id", "type", "name", "url"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stable identifier for the resource, unique within the feed."
        },
        "type": {
          "type": "string",
          "minLength": 1,
          "description": "Open, schema.org-inspired resource type. Well-known values include Boat, Course, BoatTrip, Event and Service, but this list is not exhaustive and is not enforced by this schema."
        },
        "name": { "type": "string", "minLength": 1 },
        "description": { "type": "string" },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Informational URL: tells you more about this resource. Distinct from an Offer's url, which lets you book it."
        },
        "offers": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/offer" }
        },
        "schedule": { "$ref": "#/$defs/schedule" }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": {}
      },
      "oneOf": [
        {
          "required": ["offers"],
          "not": { "required": ["schedule"] }
        },
        {
          "required": ["schedule"],
          "not": { "required": ["offers"] }
        }
      ]
    },
    "offer": {
      "type": "object",
      "description": "A concrete, bookable instance of a resource: a specific date, price and capacity.",
      "required": ["id", "price", "priceCurrency", "starts", "ends", "url"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stable identifier for the offer, unique within the resource."
        },
        "name": { "type": "string" },
        "price": { "type": "number", "minimum": 0 },
        "priceCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "ISO 4217 currency code, e.g. EUR."
        },
        "starts": {
          "type": "string",
          "format": "date-time",
          "description": "Absolute start instant of this specific offer."
        },
        "ends": {
          "type": "string",
          "format": "date-time",
          "description": "Absolute end instant of this specific offer."
        },
        "capacity": { "type": "integer", "minimum": 0 },
        "remaining": { "type": "integer", "minimum": 0 },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Transactional URL: books this specific offer. Distinct from a Resource's url, which is informational only."
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": {}
      }
    },
    "schedule": {
      "type": "object",
      "description": "A compact way to publish recurring availability: a set of reusable time-slot options, plus which options are available on which dates.",
      "required": ["options", "availability"],
      "properties": {
        "options": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/option" }
        },
        "availability": {
          "type": "object",
          "description": "Maps an ISO 8601 date to the ids of the options available that day. An option id used here MUST correspond to an option in the same schedule's 'options' array; this schema does not enforce that cross-reference.",
          "patternProperties": {
            "^\\d{4}-\\d{2}-\\d{2}$": {
              "type": "array",
              "items": { "type": "string", "minLength": 1 }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": {}
      }
    },
    "option": {
      "type": "object",
      "description": "A reusable time-slot template, e.g. 'the morning slot'. Options are referenced by id from a schedule's availability map.",
      "required": ["id", "starts", "ends", "price", "priceCurrency"],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Stable identifier for the option, unique within the resource's schedule."
        },
        "name": { "type": "string" },
        "starts": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
          "description": "Time of day this option starts, as HH:MM, 24-hour (not a date-time: options are reused across many dates)."
        },
        "ends": {
          "type": "string",
          "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
          "description": "Time of day this option ends, as HH:MM, 24-hour (not a date-time: options are reused across many dates)."
        },
        "price": { "type": "number", "minimum": 0 },
        "priceCurrency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "ISO 4217 currency code, e.g. EUR."
        }
      },
      "additionalProperties": false,
      "patternProperties": {
        "^x-": {}
      }
    }
  }
}
