{
  "openapi": "3.1.0",
  "info": {
    "title": "Coachat Public Merchant Map API",
    "version": "1.0.0",
    "description": "Public read-only API used by the homepage interactive map and discoverable by AI agents."
  },
  "servers": [
    {
      "url": "https://la-carte-api.coachat.fr/api"
    }
  ],
  "paths": {
    "/public/merchants/map": {
      "get": {
        "summary": "Get merchants for map viewport",
        "description": "Returns merchants with coordinates, loyalty programs, active offers, and subscribe URL.",
        "parameters": [
          { "name": "lat", "in": "query", "schema": { "type": "number" } },
          { "name": "lng", "in": "query", "schema": { "type": "number" } },
          { "name": "sw_lat", "in": "query", "schema": { "type": "number" } },
          { "name": "sw_lng", "in": "query", "schema": { "type": "number" } },
          { "name": "ne_lat", "in": "query", "schema": { "type": "number" } },
          { "name": "ne_lng", "in": "query", "schema": { "type": "number" } }
        ],
        "responses": {
          "200": {
            "description": "Merchant map payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "merchants": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/PublicMapMerchant" }
                    }
                  },
                  "required": ["merchants"]
                }
              }
            }
          },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/public/merchants/search": {
      "get": {
        "summary": "Search merchants",
        "parameters": [
          { "name": "q", "in": "query", "required": true, "schema": { "type": "string", "minLength": 3 } },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 10, "default": 5 } },
          { "name": "lat", "in": "query", "schema": { "type": "number" } },
          { "name": "lng", "in": "query", "schema": { "type": "number" } }
        ],
        "responses": {
          "200": {
            "description": "Search payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "merchants": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/PublicSearchMerchant" }
                    }
                  },
                  "required": ["merchants"]
                }
              }
            }
          },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/public/merchants/{id}": {
      "get": {
        "summary": "Get one merchant detail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "Merchant details",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/PublicMapMerchant" }
              }
            }
          },
          "404": { "description": "Merchant not found" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "LoyaltyProgram": {
        "type": "object",
        "properties": {
          "id": { "type": ["integer", "string"] },
          "name": { "type": "string" },
          "type": { "type": "string", "enum": ["STAMP", "POINTS"] },
          "stamp_target": { "type": ["integer", "null"] },
          "points_target": { "type": ["integer", "null"] },
          "reward_description": { "type": ["string", "null"] }
        },
        "required": ["id", "name", "type"]
      },
      "ActiveOffer": {
        "type": "object",
        "properties": {
          "id": { "type": ["integer", "string"] },
          "title": { "type": "string" },
          "description": { "type": "string" },
          "ends_on": { "type": ["string", "null"], "format": "date" }
        },
        "required": ["id", "title", "description"]
      },
      "GoogleReview": {
        "type": "object",
        "properties": {
          "is_enabled": { "type": "boolean" },
          "display_name": { "type": ["string", "null"] },
          "url": { "type": ["string", "null"], "format": "uri" }
        },
        "required": ["is_enabled"]
      },
      "PublicMapMerchant": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "company_name": { "type": "string" },
          "address": { "type": ["string", "null"] },
          "postal_code": { "type": ["string", "null"] },
          "city": { "type": ["string", "null"] },
          "phone": { "type": ["string", "null"] },
          "logo_url": { "type": ["string", "null"] },
          "latitude": { "type": "number" },
          "longitude": { "type": "number" },
          "distance_km": { "type": ["number", "null"] },
          "has_active_content": { "type": "boolean" },
          "loyalty_programs": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/LoyaltyProgram" }
          },
          "active_promotional_offers": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ActiveOffer" }
          },
          "google_review": {
            "oneOf": [
              { "$ref": "#/components/schemas/GoogleReview" },
              { "type": "null" }
            ]
          },
          "subscribe_url": { "type": "string" }
        },
        "required": ["id", "company_name", "latitude", "longitude", "loyalty_programs", "active_promotional_offers", "subscribe_url"]
      },
      "PublicSearchMerchant": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "company_name": { "type": "string" },
          "address": { "type": ["string", "null"] },
          "postal_code": { "type": ["string", "null"] },
          "city": { "type": ["string", "null"] },
          "latitude": { "type": "number" },
          "longitude": { "type": "number" },
          "distance_km": { "type": ["number", "null"] },
          "has_loyalty_programs": { "type": "boolean" },
          "has_active_promotional_offers": { "type": "boolean" },
          "subscribe_url": { "type": "string" }
        },
        "required": ["id", "company_name", "latitude", "longitude", "subscribe_url"]
      }
    }
  }
}
