{
  "openapi": "3.1.0",
  "info": {
    "title": "Djinn Audit Trail",
    "description": "Journal d'audit immutable et conformité RGPD",
    "version": "0.1.0"
  },
  "paths": {
    "/health": {
      "get": {
        "summary": "Health",
        "description": "Health check endpoint.",
        "operationId": "health_health_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events": {
      "post": {
        "summary": "Create Event",
        "description": "Record a single audit event.",
        "operationId": "create_event_v1_events_post",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AuditEventCreate"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuditEvent"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "Query Events",
        "description": "Query audit events with filters.",
        "operationId": "query_events_v1_events_get",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "tenant_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Tenant Id"
            }
          },
          {
            "name": "actor_id",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Actor Id"
            }
          },
          {
            "name": "action",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Action"
            }
          },
          {
            "name": "resource_type",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Resource Type"
            }
          },
          {
            "name": "resource_id",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Resource Id"
            }
          },
          {
            "name": "severity",
            "in": "query",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "$ref": "#/components/schemas/AuditSeverity"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Severity"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "maximum": 1000,
              "minimum": 1,
              "default": 50,
              "title": "Limit"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0,
              "title": "Offset"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/AuditEvent"
                  },
                  "title": "Response Query Events V1 Events Get"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/events/batch": {
      "post": {
        "summary": "Create Events Batch",
        "description": "Record multiple audit events.",
        "operationId": "create_events_batch_v1_events_batch_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchCreateRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchCreateResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "APIKeyHeader": []
          }
        ]
      }
    },
    "/v1/events/{event_id}": {
      "get": {
        "summary": "Get Event",
        "description": "Get a single audit event by ID, scoped to a tenant.",
        "operationId": "get_event_v1_events__event_id__get",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "event_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Event Id"
            }
          },
          {
            "name": "tenant_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Tenant Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuditEvent"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/gdpr/export": {
      "post": {
        "summary": "Gdpr Export",
        "description": "Export all data for a subject (RGPD droit d'accès).",
        "operationId": "gdpr_export_v1_gdpr_export_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GDPRExportRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GDPRExportResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "APIKeyHeader": []
          }
        ]
      }
    },
    "/v1/gdpr/anonymize": {
      "post": {
        "summary": "Gdpr Anonymize",
        "description": "Anonymize a data subject (RGPD droit à l'oubli).",
        "operationId": "gdpr_anonymize_v1_gdpr_anonymize_post",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GDPRAnonymizeRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnonymizeResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        },
        "security": [
          {
            "APIKeyHeader": []
          }
        ]
      }
    },
    "/v1/stats": {
      "get": {
        "summary": "Stats",
        "description": "Get audit statistics for a tenant.",
        "operationId": "stats_v1_stats_get",
        "security": [
          {
            "APIKeyHeader": []
          }
        ],
        "parameters": [
          {
            "name": "tenant_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "title": "Tenant Id"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true,
                  "title": "Response Stats V1 Stats Get"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "AnonymizeResponse": {
        "properties": {
          "anonymized_count": {
            "type": "integer",
            "title": "Anonymized Count"
          },
          "subject_id": {
            "type": "string",
            "title": "Subject Id"
          }
        },
        "type": "object",
        "required": [
          "anonymized_count",
          "subject_id"
        ],
        "title": "AnonymizeResponse",
        "description": "Réponse d'anonymisation."
      },
      "AuditEvent": {
        "properties": {
          "tenant_id": {
            "type": "string",
            "title": "Tenant Id"
          },
          "actor_id": {
            "type": "string",
            "title": "Actor Id",
            "description": "ID de l'auteur de l'action"
          },
          "actor_type": {
            "type": "string",
            "title": "Actor Type",
            "description": "user | system | api_key",
            "default": "user"
          },
          "action": {
            "type": "string",
            "title": "Action",
            "description": "create | read | update | delete | export | login | ..."
          },
          "resource_type": {
            "type": "string",
            "title": "Resource Type",
            "description": "invoice | contract | user | ..."
          },
          "resource_id": {
            "type": "string",
            "title": "Resource Id",
            "description": "ID de la ressource concernée"
          },
          "changes": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Changes",
            "description": "Changements : {field: {old: x, new: y}}"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object",
            "title": "Metadata",
            "description": "IP, user-agent, request_id, etc."
          },
          "severity": {
            "$ref": "#/components/schemas/AuditSeverity",
            "default": "info"
          },
          "id": {
            "type": "string",
            "title": "Id"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "title": "Timestamp"
          },
          "anonymized": {
            "type": "boolean",
            "title": "Anonymized",
            "default": false
          }
        },
        "type": "object",
        "required": [
          "tenant_id",
          "actor_id",
          "action",
          "resource_type",
          "resource_id",
          "id",
          "timestamp"
        ],
        "title": "AuditEvent",
        "description": "Événement d'audit complet avec ID et timestamp."
      },
      "AuditEventCreate": {
        "properties": {
          "tenant_id": {
            "type": "string",
            "title": "Tenant Id"
          },
          "actor_id": {
            "type": "string",
            "title": "Actor Id",
            "description": "ID de l'auteur de l'action"
          },
          "actor_type": {
            "type": "string",
            "title": "Actor Type",
            "description": "user | system | api_key",
            "default": "user"
          },
          "action": {
            "type": "string",
            "title": "Action",
            "description": "create | read | update | delete | export | login | ..."
          },
          "resource_type": {
            "type": "string",
            "title": "Resource Type",
            "description": "invoice | contract | user | ..."
          },
          "resource_id": {
            "type": "string",
            "title": "Resource Id",
            "description": "ID de la ressource concernée"
          },
          "changes": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Changes",
            "description": "Changements : {field: {old: x, new: y}}"
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object",
            "title": "Metadata",
            "description": "IP, user-agent, request_id, etc."
          },
          "severity": {
            "$ref": "#/components/schemas/AuditSeverity",
            "default": "info"
          }
        },
        "type": "object",
        "required": [
          "tenant_id",
          "actor_id",
          "action",
          "resource_type",
          "resource_id"
        ],
        "title": "AuditEventCreate",
        "description": "Requête de création d'un événement d'audit."
      },
      "AuditSeverity": {
        "type": "string",
        "enum": [
          "info",
          "warning",
          "critical"
        ],
        "title": "AuditSeverity",
        "description": "Niveau de sévérité d'un événement."
      },
      "BatchCreateRequest": {
        "properties": {
          "events": {
            "items": {
              "$ref": "#/components/schemas/AuditEventCreate"
            },
            "type": "array",
            "minItems": 1,
            "title": "Events"
          }
        },
        "type": "object",
        "required": [
          "events"
        ],
        "title": "BatchCreateRequest",
        "description": "Requête de création d'événements en batch."
      },
      "BatchCreateResponse": {
        "properties": {
          "created": {
            "type": "integer",
            "title": "Created"
          },
          "events": {
            "items": {
              "$ref": "#/components/schemas/AuditEvent"
            },
            "type": "array",
            "title": "Events"
          }
        },
        "type": "object",
        "required": [
          "created",
          "events"
        ],
        "title": "BatchCreateResponse",
        "description": "Réponse de création en batch."
      },
      "GDPRAnonymizeRequest": {
        "properties": {
          "tenant_id": {
            "type": "string",
            "title": "Tenant Id"
          },
          "subject_id": {
            "type": "string",
            "title": "Subject Id",
            "description": "ID de la personne à anonymiser"
          },
          "subject_type": {
            "type": "string",
            "enum": [
              "actor_id",
              "resource_id"
            ],
            "title": "Subject Type",
            "description": "Champ à anonymiser : actor_id | resource_id",
            "default": "actor_id"
          },
          "replacement": {
            "type": "string",
            "title": "Replacement",
            "description": "Valeur de remplacement",
            "default": "[ANONYMIZED]"
          }
        },
        "type": "object",
        "required": [
          "tenant_id",
          "subject_id"
        ],
        "title": "GDPRAnonymizeRequest",
        "description": "Requête d'anonymisation des données personnelles."
      },
      "GDPRExportRequest": {
        "properties": {
          "tenant_id": {
            "type": "string",
            "title": "Tenant Id"
          },
          "subject_id": {
            "type": "string",
            "title": "Subject Id",
            "description": "ID de la personne concernee"
          },
          "subject_type": {
            "type": "string",
            "enum": [
              "actor_id",
              "resource_id"
            ],
            "title": "Subject Type",
            "description": "Champ a chercher : actor_id | resource_id",
            "default": "actor_id"
          }
        },
        "type": "object",
        "required": [
          "tenant_id",
          "subject_id"
        ],
        "title": "GDPRExportRequest",
        "description": "Requête d'export des données personnelles (droit d'accès RGPD)."
      },
      "GDPRExportResponse": {
        "properties": {
          "subject_id": {
            "type": "string",
            "title": "Subject Id"
          },
          "event_count": {
            "type": "integer",
            "title": "Event Count"
          },
          "events": {
            "items": {
              "additionalProperties": true,
              "type": "object"
            },
            "type": "array",
            "title": "Events"
          }
        },
        "type": "object",
        "required": [
          "subject_id",
          "event_count",
          "events"
        ],
        "title": "GDPRExportResponse",
        "description": "Réponse d'export RGPD."
      },
      "HTTPValidationError": {
        "properties": {
          "detail": {
            "items": {
              "$ref": "#/components/schemas/ValidationError"
            },
            "type": "array",
            "title": "Detail"
          }
        },
        "type": "object",
        "title": "HTTPValidationError"
      },
      "HealthResponse": {
        "properties": {
          "status": {
            "type": "string",
            "title": "Status",
            "default": "ok"
          },
          "service": {
            "type": "string",
            "title": "Service",
            "default": "audit-trail"
          },
          "version": {
            "type": "string",
            "title": "Version",
            "default": "0.1.0"
          }
        },
        "type": "object",
        "title": "HealthResponse",
        "description": "Response for health check."
      },
      "ValidationError": {
        "properties": {
          "loc": {
            "items": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "type": "array",
            "title": "Location"
          },
          "msg": {
            "type": "string",
            "title": "Message"
          },
          "type": {
            "type": "string",
            "title": "Error Type"
          },
          "input": {
            "title": "Input"
          },
          "ctx": {
            "type": "object",
            "title": "Context"
          }
        },
        "type": "object",
        "required": [
          "loc",
          "msg",
          "type"
        ],
        "title": "ValidationError"
      }
    },
    "securitySchemes": {
      "APIKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  }
}
