{
  "openapi": "3.1.0",
  "info": {
    "title": "en-tri Integration API",
    "version": "0.1.0",
    "description": "Public integration API for listing channel events and selling spots through en-tri. en-tri owns booking, payment, capacity, and roster state; channels own discovery and presentation."
  },
  "servers": [
    {
      "url": "https://en-tri.com"
    }
  ],
  "paths": {
    "/api/channels/{channelSlug}/events": {
      "get": {
        "summary": "List upcoming events enabled for a distribution channel",
        "parameters": [
          {
            "name": "channelSlug",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "examples": {
              "foot7": { "value": "foot7" },
              "ourExcuse": { "value": "our-excuse" },
              "padelClique": { "value": "padelclique" }
            }
          },
          {
            "name": "organiser",
            "in": "query",
            "required": false,
            "schema": { "type": "string" },
            "description": "Optional organiser slug filter."
          }
        ],
        "responses": {
          "200": {
            "description": "Channel event feed",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChannelEventsResponse" }
              }
            }
          },
          "404": {
            "description": "Unknown channel",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChannelEventsResponse" }
              }
            }
          }
        }
      }
    },
    "/api/channels/{channelSlug}/bookings": {
      "post": {
        "summary": "Create a confirmed or waitlisted booking for a channel event",
        "description": "Use this for free, offline-paid, or externally-paid native partner bookings. en-tri owns capacity, roster, waitlist, notifications, and attribution.",
        "parameters": [
          {
            "name": "channelSlug",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "examples": {
              "padelClique": { "value": "padelclique" },
              "foot7": { "value": "foot7" }
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Partner-generated booking key. Repeated requests for the same event, channel, and key return the original booking."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateChannelBookingRequest" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Booking created",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreateChannelBookingResponse" }
              }
            }
          },
          "200": {
            "description": "Idempotent replay of an existing booking",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreateChannelBookingResponse" }
              }
            }
          },
          "400": { "description": "Invalid request" },
          "404": { "description": "Channel or event not found" }
        }
      }
    },
    "/api/channels/{channelSlug}/events/{organiserSlug}/{eventSlug}/bookings": {
      "get": {
        "summary": "List public booking names for a channel event",
        "description": "Use this to render a public roster on a native channel event page. It returns display names and booking status only; it does not expose email, phone, notes, payment ids, or organiser-only fields.",
        "parameters": [
          {
            "name": "channelSlug",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "examples": {
              "padelClique": { "value": "padelclique" }
            }
          },
          { "$ref": "#/components/parameters/OrganiserSlug" },
          { "$ref": "#/components/parameters/EventSlug" }
        ],
        "responses": {
          "200": {
            "description": "Public event roster",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChannelEventBookingsResponse" }
              }
            }
          },
          "404": {
            "description": "Channel or event not found",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ChannelEventBookingsResponse" }
              }
            }
          }
        }
      }
    },
    "/api/foot7/events": {
      "get": {
        "summary": "Legacy Foot7 event feed",
        "description": "Backwards-compatible endpoint. New integrations should use /api/channels/foot7/events.",
        "parameters": [
          {
            "name": "organiser",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "default": "futbol-amistoso" }
          }
        ],
        "responses": {
          "200": {
            "description": "Foot7 event feed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "organiser": { "$ref": "#/components/schemas/OrganiserSummary" },
                    "events": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/EventSummary" }
                    }
                  },
                  "required": ["organiser", "events"]
                }
              }
            }
          }
        }
      }
    },
    "/api/payment-intent/{organiserSlug}/{eventSlug}": {
      "post": {
        "summary": "Create a Stripe Payment Intent for a paid event",
        "parameters": [
          { "$ref": "#/components/parameters/OrganiserSlug" },
          { "$ref": "#/components/parameters/EventSlug" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreatePaymentIntentRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment Intent details for client-side Stripe confirmation",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreatePaymentIntentResponse" }
              }
            }
          },
          "400": { "description": "Missing attendee details or event is free" },
          "404": { "description": "Event not found" },
          "409": { "description": "Event is sold out" },
          "503": { "description": "Payments unavailable" }
        }
      }
    },
    "/api/payment-confirm/{organiserSlug}/{eventSlug}": {
      "post": {
        "summary": "Confirm a Stripe Payment Intent and mark booking confirmed",
        "parameters": [
          { "$ref": "#/components/parameters/OrganiserSlug" },
          { "$ref": "#/components/parameters/EventSlug" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paymentIntentId": { "type": "string" }
                },
                "required": ["paymentIntentId"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Booking confirmed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "ok": { "const": true } },
                  "required": ["ok"]
                }
              }
            }
          },
          "409": {
            "description": "Payment exists but is not succeeded yet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "const": false },
                    "status": { "type": "string" }
                  },
                  "required": ["ok", "status"]
                }
              }
            }
          }
        }
      }
    },
    "/api/booking-followup/{organiserSlug}/{eventSlug}": {
      "post": {
        "summary": "Attach optional email and note after payment",
        "parameters": [
          { "$ref": "#/components/parameters/OrganiserSlug" },
          { "$ref": "#/components/parameters/EventSlug" }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "paymentIntentId": { "type": "string" },
                  "email": { "type": "string", "format": "email" },
                  "note": { "type": "string" }
                },
                "required": ["paymentIntentId"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Follow-up saved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "ok": { "const": true } },
                  "required": ["ok"]
                }
              }
            }
          },
          "400": { "description": "Invalid request" },
          "404": { "description": "Booking not found" }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "OrganiserSlug": {
        "name": "organiserSlug",
        "in": "path",
        "required": true,
        "schema": { "type": "string" }
      },
      "EventSlug": {
        "name": "eventSlug",
        "in": "path",
        "required": true,
        "schema": { "type": "string" }
      }
    },
    "schemas": {
      "Channel": {
        "type": "object",
        "properties": {
          "slug": { "type": "string" },
          "name": { "type": "string" },
          "origin": { "type": "string", "format": "uri" }
        },
        "required": ["slug", "name", "origin"]
      },
      "OrganiserSummary": {
        "type": "object",
        "properties": {
          "name": { "type": ["string", "null"] },
          "slug": { "type": "string" },
          "currency": { "type": "string" }
        },
        "required": ["name", "slug", "currency"]
      },
      "EventSummary": {
        "type": "object",
        "properties": {
          "organiserSlug": { "type": "string" },
          "organiserName": { "type": ["string", "null"] },
          "eventSlug": { "type": "string" },
          "title": { "type": "string" },
          "description": { "type": ["string", "null"] },
          "date": { "type": "string", "format": "date" },
          "startTime": { "type": "string" },
          "endTime": { "type": ["string", "null"] },
          "priceCents": { "type": "integer" },
          "currency": { "type": "string" },
          "spotsTotal": { "type": "integer" },
          "spotsRemaining": { "type": "integer" },
          "placeName": { "type": ["string", "null"] },
          "placeAddress": { "type": ["string", "null"] },
          "placeId": { "type": ["string", "null"] },
          "lat": { "type": ["number", "null"] },
          "lng": { "type": ["number", "null"] },
          "canonicalUrl": { "type": "string", "format": "uri" },
          "embedUrl": { "type": "string", "format": "uri" }
        },
        "required": [
          "organiserSlug",
          "organiserName",
          "eventSlug",
          "title",
          "description",
          "date",
          "startTime",
          "endTime",
          "priceCents",
          "currency",
          "spotsTotal",
          "spotsRemaining",
          "placeName",
          "placeAddress",
          "placeId",
          "lat",
          "lng",
          "canonicalUrl",
          "embedUrl"
        ]
      },
      "ChannelEventsResponse": {
        "type": "object",
        "properties": {
          "channel": {
            "oneOf": [
              { "$ref": "#/components/schemas/Channel" },
              { "type": "null" }
            ]
          },
          "organisers": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/OrganiserSummary" }
          },
          "organiser": {
            "oneOf": [
              { "$ref": "#/components/schemas/OrganiserSummary" },
              { "type": "null" }
            ]
          },
          "events": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/EventSummary" }
          }
        },
        "required": ["channel", "organisers", "events"]
      },
      "ChannelEventBookingsResponse": {
        "type": "object",
        "properties": {
          "spotsTotal": { "type": "integer" },
          "bookings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "position": { "type": "integer" },
                "name": { "type": "string" },
                "status": { "type": "string", "enum": ["confirmed", "waitlisted"] },
                "guests": { "type": "integer" }
              },
              "required": ["position", "name", "status", "guests"]
            }
          }
        },
        "required": ["bookings"]
      },
      "CreatePaymentIntentRequest": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "phone": { "type": "string" },
          "signupSource": {
            "type": "string",
            "enum": ["en-tri", "embed", "api", "manual"]
          },
          "signupChannel": { "type": ["string", "null"] },
          "signupOrigin": { "type": ["string", "null"] },
          "signupReferrer": { "type": ["string", "null"] }
        },
        "required": ["name", "phone"]
      },
      "CreatePaymentIntentResponse": {
        "type": "object",
        "properties": {
          "clientSecret": { "type": "string" },
          "paymentIntentId": { "type": "string" },
          "publishableKey": { "type": "string" },
          "stripeAccount": { "type": "string" }
        },
        "required": ["clientSecret", "paymentIntentId", "publishableKey", "stripeAccount"]
      },
      "CreateChannelBookingRequest": {
        "type": "object",
        "properties": {
          "organiserSlug": { "type": "string" },
          "eventSlug": { "type": "string" },
          "name": { "type": "string" },
          "email": { "type": ["string", "null"], "format": "email" },
          "phone": { "type": ["string", "null"] },
          "guests": { "type": "integer", "minimum": 0, "default": 0 },
          "note": { "type": ["string", "null"] },
          "waitlist": { "type": "boolean", "default": false },
          "idempotencyKey": { "type": ["string", "null"] },
          "signupOrigin": { "type": ["string", "null"], "format": "uri" },
          "signupReferrer": { "type": ["string", "null"], "format": "uri" }
        },
        "required": ["organiserSlug", "eventSlug", "name"]
      },
      "CreateChannelBookingResponse": {
        "type": "object",
        "properties": {
          "ok": { "const": true },
          "idempotent": { "type": "boolean" },
          "booking": {
            "type": "object",
            "properties": {
              "id": { "type": "string" },
              "status": { "type": "string", "enum": ["confirmed", "waitlisted"] },
              "name": { "type": ["string", "null"] },
              "email": { "type": ["string", "null"], "format": "email" },
              "phone": { "type": ["string", "null"] },
              "guests": { "type": "integer" }
            },
            "required": ["id", "status", "name", "email", "phone", "guests"]
          },
          "event": {
            "type": "object",
            "properties": {
              "organiserSlug": { "type": "string" },
              "eventSlug": { "type": "string" },
              "title": { "type": "string" },
              "spotsRemaining": { "type": "integer" }
            },
            "required": ["organiserSlug", "eventSlug", "title", "spotsRemaining"]
          }
        },
        "required": ["ok", "booking"]
      }
    }
  }
}
