{
  "openapi": "3.1.0",
  "info": {
    "title": "Léon et fils Contact Request API",
    "version": "1.0.0",
    "description": "Public and OAuth-protected APIs for submitting contact requests to Léon et fils."
  },
  "servers": [
    {
      "url": "https://www.leonetfils-plomberie.fr"
    }
  ],
  "paths": {
    "/api/contact-request": {
      "post": {
        "summary": "Submit a contact request",
        "description": "Sends a contact request to Léon et fils for plumbing or heating work.",
        "operationId": "submitContactRequest",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Contact request accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AcceptedResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Delivery failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/contact-request-secure": {
      "post": {
        "summary": "Submit an authenticated contact request",
        "description": "Sends a contact request for trusted agent integrations using OAuth 2.0 client credentials.",
        "operationId": "submitSecureContactRequest",
        "security": [
          {
            "oauthClientCredentials": [
              "contact:write"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/ContactRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Authenticated contact request accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SecureAcceptedResponse"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Bearer token does not grant the required scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationErrorResponse"
                }
              }
            }
          },
          "503": {
            "description": "Delivery failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeliveryErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "summary": "Health check",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "Service health status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauthClientCredentials": {
        "type": "oauth2",
        "description": "OAuth 2.0 client credentials flow for trusted agent integrations.",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://www.leonetfils-plomberie.fr/oauth/token",
            "scopes": {
              "contact:write": "Submit authenticated contact requests."
            }
          }
        }
      }
    },
    "schemas": {
      "ContactRequest": {
        "type": "object",
        "required": [
          "name",
          "phone",
          "location",
          "consent"
        ],
        "properties": {
          "name": {
            "type": "string",
            "minLength": 2
          },
          "phone": {
            "type": "string",
            "minLength": 1
          },
          "location": {
            "type": "string",
            "minLength": 2
          },
          "message": {
            "type": "string"
          },
          "consent": {
            "oneOf": [
              {
                "type": "boolean"
              },
              {
                "type": "string",
                "enum": [
                  "1",
                  "true",
                  "yes",
                  "on"
                ]
              },
              {
                "type": "integer",
                "enum": [
                  1
                ]
              }
            ]
          }
        }
      },
      "AcceptedResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "accepted"
          },
          "message": {
            "type": "string"
          },
          "contact": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "location": {
                "type": "string"
              }
            }
          }
        }
      },
      "SecureAcceptedResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "accepted"
          },
          "message": {
            "type": "string"
          },
          "authenticated_client": {
            "type": "string"
          },
          "contact": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "location": {
                "type": "string"
              }
            }
          }
        }
      },
      "AuthErrorResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "error"
          },
          "reason": {
            "type": "string",
            "enum": [
              "invalid_token",
              "insufficient_scope",
              "server_error"
            ]
          },
          "message": {
            "type": "string"
          }
        }
      },
      "ValidationErrorResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "error"
          },
          "reason": {
            "type": "string",
            "const": "validation"
          },
          "message": {
            "type": "string"
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "DeliveryErrorResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "error"
          },
          "reason": {
            "type": "string",
            "const": "mail"
          },
          "message": {
            "type": "string"
          },
          "fallback": {
            "type": "object",
            "properties": {
              "telephone": {
                "type": "string"
              },
              "email": {
                "type": "string",
                "format": "email"
              }
            }
          }
        }
      },
      "HealthResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "const": "ok"
          },
          "service": {
            "type": "string"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}
