{
  "openapi": "3.1.0",
  "info": {
    "title": "MIUI Decrypt API",
    "description": "Decrypt MIUI Gallery .lsa and .lsav encrypted files. Upload, process, and download decrypted media through an automated pipeline.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://lsadecrypt.online",
      "description": "Production server"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "responses": {
          "200": { "description": "OK" }
        }
      }
    },
    "/api/get-upload-url": {
      "post": {
        "summary": "Get presigned S3 upload URL",
        "operationId": "getUploadUrl",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["fileName", "fileSize"],
                "properties": {
                  "fileName": { "type": "string", "description": "Original filename (.lsa or .lsav)" },
                  "fileSize": { "type": "integer", "description": "File size in bytes" },
                  "source": { "type": "string", "enum": ["mcp"], "description": "Upload origin for analytics. 'mcp' when submitted via MCP server, omitted for web client uploads" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload URL and job details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uploadUrl": { "type": "string", "format": "uri" },
                    "fileKey": { "type": "string" },
                    "jobId": { "type": "string", "format": "uuid" },
                    "isGuest": { "type": "boolean" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/process": {
      "post": {
        "summary": "Start decryption job",
        "operationId": "startDecryption",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["fileKey", "fileName", "fileSize", "jobId"],
                "properties": {
                  "fileKey": { "type": "string" },
                  "fileName": { "type": "string" },
                  "fileSize": { "type": "integer" },
                  "jobId": { "type": "string", "format": "uuid" },
                  "source": { "type": "string", "enum": ["mcp"], "description": "Upload origin for analytics. 'mcp' when submitted via MCP server, omitted for web client uploads" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Job created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "jobId": { "type": "string", "format": "uuid" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/media-status/{jobId}": {
      "get": {
        "summary": "Poll decryption job status (SSE)",
        "operationId": "getJobStatus",
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "SSE stream with status updates",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string", "format": "uuid" },
                    "status": { "type": "string", "enum": ["pending", "processing", "complete", "error"] },
                    "progress": { "type": "integer", "minimum": 0, "maximum": 100 },
                    "previewUrl": { "type": "string", "format": "uri" },
                    "isVideo": { "type": "boolean" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/media/{fileId}": {
      "get": {
        "summary": "Stream decrypted media file",
        "operationId": "getMediaFile",
        "parameters": [
          {
            "name": "fileId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "type",
            "in": "query",
            "schema": { "type": "string", "enum": ["preview", "original", "videoPreview"] },
            "description": "Media type to stream"
          }
        ],
        "responses": {
          "200": { "description": "Media file stream" },
          "206": { "description": "Partial content (Range request)" },
          "400": { "description": "Missing or invalid parameters" },
          "401": { "description": "Unauthorized" },
          "403": { "description": "Access forbidden" },
          "404": { "description": "File not found" }
        }
      }
    },
    "/api/pricing": {
      "get": {
        "summary": "Get credit pack pricing",
        "operationId": "getPricing",
        "responses": {
          "200": {
            "description": "Pricing data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "prices": { "type": "object" },
                    "regions": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create Stripe checkout session",
        "operationId": "createCheckoutSession",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["packId", "quantity"],
                "properties": {
                  "packId": { "type": "string" },
                  "quantity": { "type": "integer", "minimum": 1 },
                  "returnTo": { "type": "string" },
                  "selectedFileIds": { "type": "array", "items": { "type": "string" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "url": { "type": "string", "format": "uri" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/purchase-files": {
      "post": {
        "summary": "Purchase original-quality file downloads",
        "operationId": "purchaseFiles",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["fileIds"],
                "properties": {
                  "fileIds": { "type": "array", "items": { "type": "string" } }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Purchase session created" }
        }
      }
    },
    "/api/active-jobs": {
      "get": {
        "summary": "List active decryption jobs for the current user",
        "operationId": "getActiveJobs",
        "responses": {
          "200": {
            "description": "Array of active jobs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "string", "format": "uuid" },
                      "fileName": { "type": "string" },
                      "fileSize": { "type": "integer" },
                      "status": { "type": "string" },
                      "progress": { "type": "integer" },
                      "createdAt": { "type": "string", "format": "date-time" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/jobs-stats": {
      "get": {
        "summary": "Get decryption job statistics",
        "operationId": "getJobStats",
        "responses": {
          "200": {
            "description": "Job statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total": { "type": "integer" },
                    "completed": { "type": "integer" },
                    "failed": { "type": "integer" },
                    "active": { "type": "integer" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/transactions": {
      "get": {
        "summary": "Get payment transaction history",
        "operationId": "getTransactions",
        "responses": {
          "200": {
            "description": "Transaction history",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": { "type": "string" },
                      "amount": { "type": "number" },
                      "currency": { "type": "string" },
                      "status": { "type": "string" },
                      "createdAt": { "type": "string", "format": "date-time" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
