{
  "openapi": "3.1.0",
  "info": {
    "title": "Cedar Parcel API",
    "version": "1.0.0"
  },
  "tags": [
    {
      "name": "Enrollment",
      "description": "Set up a parcel program."
    }
  ],
  "paths": {
    "/Enrollments": {
      "post": {
        "tags": [
          "Enrollment"
        ],
        "summary": "Create a parcel enrollment",
        "description": "Create one of four enrollment shapes. The service accepts different\nrequired fields for each program; the examples illustrate the shapes\nbut have not been sent to a server.\n",
        "operationId": "createEnrollment",
        "requestBody": {
          "required": true,
          "description": "Choose the program that matches the parcels you will dispatch.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateEnrollment"
              },
              "examples": {
                "localShop": {
                  "summary": "Local shop",
                  "description": "A storefront with standard pickup windows.",
                  "value": {
                    "program": "local",
                    "organization": {
                      "displayName": "Example Corner Shop",
                      "address": {
                        "line1": "12 Sample Lane",
                        "city": "Northport",
                        "region": "NP",
                        "postalCode": "00012"
                      }
                    },
                    "contact": {
                      "name": "Taylor Example",
                      "email": "taylor@example.com"
                    },
                    "pickupWindows": [
                      {
                        "day": "monday",
                        "opensAt": "09:00",
                        "closesAt": "17:00"
                      }
                    ]
                  }
                },
                "chilledGoods": {
                  "summary": "Chilled goods",
                  "value": {
                    "program": "chilled",
                    "organization": {
                      "displayName": "Demo Cold Store",
                      "address": {
                        "line1": "9 Test Quay",
                        "city": "Northport",
                        "region": "NP",
                        "postalCode": "00019"
                      }
                    },
                    "contact": {
                      "name": "Robin Sample",
                      "email": "robin@example.com"
                    },
                    "temperatureRange": {
                      "minimumCelsius": 2,
                      "maximumCelsius": 6
                    },
                    "handlingNotes": "Keep upright."
                  }
                },
                "bulkDispatch": {
                  "summary": "Bulk dispatch",
                  "value": {
                    "program": "bulk",
                    "organization": {
                      "displayName": "Fictional Warehouse",
                      "address": {
                        "line1": "4 Mock Road",
                        "city": "Eastmere",
                        "region": "EM",
                        "postalCode": "00044"
                      }
                    },
                    "contact": {
                      "name": "Lee Demo",
                      "email": "lee@example.com"
                    },
                    "monthlyParcelEstimate": 12000,
                    "manifestFormat": "csv"
                  }
                },
                "combinedProgram": {
                  "summary": "Combined program",
                  "value": {
                    "program": "combined",
                    "organization": {
                      "displayName": "Synthetic Logistics",
                      "address": {
                        "line1": "8 Example Drive",
                        "city": "Eastmere",
                        "region": "EM",
                        "postalCode": "00048"
                      }
                    },
                    "contact": {
                      "name": "Morgan Test",
                      "email": "morgan@example.com"
                    },
                    "pickupWindows": [
                      {
                        "day": "friday",
                        "opensAt": "08:00",
                        "closesAt": "16:00"
                      }
                    ],
                    "temperatureRange": {
                      "minimumCelsius": 1,
                      "maximumCelsius": 7
                    },
                    "monthlyParcelEstimate": 8000,
                    "manifestFormat": "json"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The enrollment was recorded. Review may still be pending.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EnrollmentReceipt"
                },
                "examples": {
                  "pending": {
                    "summary": "Pending review",
                    "value": {
                      "enrollmentId": "enr_demo_001",
                      "status": "pending",
                      "warnings": [],
                      "approvedAt": null
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The selected program is missing one or more required fields.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApplicationKey": []
          }
        ],
        "servers": [
          {
            "url": "https://sandbox.api.cedar-parcel.example/v1",
            "description": "Enrollment sandbox only"
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "Address": {
        "type": "object",
        "required": [
          "line1",
          "city",
          "region",
          "postalCode"
        ],
        "properties": {
          "line1": {
            "type": "string",
            "description": "Street and number."
          },
          "line2": {
            "type": [
              "string",
              "null"
            ],
            "description": "Additional address line, if present."
          },
          "city": {
            "type": "string"
          },
          "region": {
            "type": "string"
          },
          "postalCode": {
            "type": "string"
          }
        }
      },
      "BulkEnrollment": {
        "type": "object",
        "required": [
          "program",
          "organization",
          "contact",
          "monthlyParcelEstimate",
          "manifestFormat"
        ],
        "properties": {
          "program": {
            "type": "string",
            "const": "bulk"
          },
          "organization": {
            "$ref": "#/components/schemas/Organization"
          },
          "contact": {
            "$ref": "#/components/schemas/Contact"
          },
          "monthlyParcelEstimate": {
            "type": "integer",
            "exclusiveMinimum": 0,
            "examples": [
              8000,
              12000
            ]
          },
          "manifestFormat": {
            "type": "string",
            "enum": [
              "csv",
              "json"
            ]
          },
          "callbackUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          },
          "customMetadata": true
        }
      },
      "ChilledEnrollment": {
        "type": "object",
        "required": [
          "program",
          "organization",
          "contact",
          "temperatureRange"
        ],
        "properties": {
          "program": {
            "type": "string",
            "const": "chilled"
          },
          "organization": {
            "$ref": "#/components/schemas/Organization"
          },
          "contact": {
            "$ref": "#/components/schemas/Contact"
          },
          "temperatureRange": {
            "$ref": "#/components/schemas/TemperatureRange"
          },
          "handlingNotes": {
            "type": "string",
            "description": "Instructions printed for handlers."
          },
          "sensorRequired": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "CombinedEnrollment": {
        "type": "object",
        "required": [
          "program",
          "organization",
          "contact",
          "pickupWindows",
          "temperatureRange",
          "monthlyParcelEstimate",
          "manifestFormat"
        ],
        "properties": {
          "program": {
            "type": "string",
            "const": "combined"
          },
          "organization": {
            "$ref": "#/components/schemas/Organization"
          },
          "contact": {
            "$ref": "#/components/schemas/Contact"
          },
          "pickupWindows": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PickupWindow"
            }
          },
          "temperatureRange": {
            "$ref": "#/components/schemas/TemperatureRange"
          },
          "monthlyParcelEstimate": {
            "type": "integer",
            "minimum": 1
          },
          "manifestFormat": {
            "type": "string",
            "enum": [
              "csv",
              "json"
            ]
          },
          "callbackUrl": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri"
          }
        }
      },
      "Contact": {
        "type": "object",
        "required": [
          "name",
          "email"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "CreateEnrollment": {
        "oneOf": [
          {
            "title": "Local pickup",
            "description": "A shop with ordinary pickup windows.",
            "$ref": "#/components/schemas/LocalEnrollment"
          },
          {
            "title": "Chilled goods",
            "description": "Requires a temperature range and handling instructions.",
            "$ref": "#/components/schemas/ChilledEnrollment"
          },
          {
            "title": "Bulk dispatch",
            "description": "Requires an estimated volume and manifest format.",
            "$ref": "#/components/schemas/BulkEnrollment"
          },
          {
            "title": "Combined program",
            "description": "Supplies pickup, temperature, and volume details.",
            "$ref": "#/components/schemas/CombinedEnrollment"
          }
        ]
      },
      "EnrollmentReceipt": {
        "type": "object",
        "required": [
          "enrollmentId",
          "status",
          "warnings",
          "approvedAt"
        ],
        "properties": {
          "enrollmentId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "approved",
              "rejected"
            ]
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "approvedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Always present; null until approved."
          }
        }
      },
      "LocalEnrollment": {
        "type": "object",
        "required": [
          "program",
          "organization",
          "contact",
          "pickupWindows"
        ],
        "properties": {
          "program": {
            "type": "string",
            "const": "local"
          },
          "organization": {
            "$ref": "#/components/schemas/Organization"
          },
          "contact": {
            "$ref": "#/components/schemas/Contact"
          },
          "pickupWindows": {
            "type": "array",
            "description": "The windows when parcels can be collected.",
            "items": {
              "$ref": "#/components/schemas/PickupWindow"
            }
          },
          "fragileHandling": {
            "type": "boolean",
            "default": false
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "Organization": {
        "type": "object",
        "required": [
          "displayName",
          "address"
        ],
        "properties": {
          "displayName": {
            "type": "string",
            "description": "Name shown on parcel labels."
          },
          "address": {
            "$ref": "#/components/schemas/Address"
          },
          "registrationCode": {
            "type": [
              "string",
              "null"
            ],
            "description": "Optional local registration code."
          }
        }
      },
      "PickupWindow": {
        "type": "object",
        "required": [
          "day",
          "opensAt",
          "closesAt"
        ],
        "properties": {
          "day": {
            "type": "string",
            "enum": [
              "monday",
              "tuesday",
              "wednesday",
              "thursday",
              "friday"
            ]
          },
          "opensAt": {
            "type": "string",
            "description": "Local time in HH:mm format."
          },
          "closesAt": {
            "type": "string",
            "description": "Local time in HH:mm format."
          }
        }
      },
      "Problem": {
        "type": "object",
        "required": [
          "type",
          "title",
          "status"
        ],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          }
        }
      },
      "TemperatureRange": {
        "type": "object",
        "required": [
          "minimumCelsius",
          "maximumCelsius"
        ],
        "properties": {
          "minimumCelsius": {
            "type": "number"
          },
          "maximumCelsius": {
            "type": "number"
          }
        }
      }
    },
    "securitySchemes": {
      "ApplicationKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Application-Key",
        "description": "Enrollment-only key."
      }
    }
  }
}
