{
  "openapi": "3.0.3",
  "info": {
    "title": "PDFPrime Mobile API",
    "version": "1.0.0",
    "description": "Secure authentication, PDF/image processing and self-hosted AI APIs for the PDFPrime Flutter application."
  },
  "servers": [{"url": "https://pdf.techicomm.com/api/v1"}],
  "security": [{"mobileBearer": []}],
  "paths": {
    "/health.php": {
      "get": {
        "security": [],
        "summary": "Health check",
        "responses": {"200": {"description": "Service is available", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Success"}}}}}
      }
    },
    "/auth/register.php": {
      "post": {
        "security": [],
        "summary": "Register and issue mobile tokens",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RegisterRequest"}}}},
        "responses": {"201": {"description": "Account created"}, "409": {"$ref": "#/components/responses/Error"}, "422": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/auth/login.php": {
      "post": {
        "security": [],
        "summary": "Log in with email and password",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/LoginRequest"}}}},
        "responses": {"200": {"description": "Authenticated"}, "401": {"$ref": "#/components/responses/Error"}, "429": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/auth/firebase.php": {
      "post": {
        "security": [],
        "summary": "Exchange a verified Firebase Google ID token",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["id_token"], "properties": {"id_token": {"type": "string"}, "device_name": {"type": "string"}}}}}},
        "responses": {"200": {"description": "Authenticated"}, "401": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/auth/refresh.php": {
      "post": {
        "security": [],
        "summary": "Rotate access and refresh tokens",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "required": ["refresh_token"], "properties": {"refresh_token": {"type": "string"}, "device_name": {"type": "string"}}}}}},
        "responses": {"200": {"description": "Token pair rotated"}, "401": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/auth/logout.php": {
      "post": {
        "summary": "Revoke current or all mobile sessions",
        "requestBody": {"content": {"application/json": {"schema": {"type": "object", "properties": {"all_devices": {"type": "boolean", "default": false}}}}}},
        "responses": {"200": {"description": "Logged out"}, "401": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/user/profile.php": {
      "get": {"summary": "Current user and plan", "responses": {"200": {"description": "Profile"}, "401": {"$ref": "#/components/responses/Error"}}}
    },
    "/user/push-token.php": {
      "post": {
        "summary": "Register or refresh a Firebase Cloud Messaging device token",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {
          "type": "object",
          "required": ["token", "platform"],
          "properties": {
            "token": {"type": "string"},
            "platform": {"type": "string", "enum": ["android", "ios", "web"]},
            "device_id": {"type": "string"},
            "app_version": {"type": "string"},
            "enabled": {"type": "boolean", "default": true}
          }
        }}}},
        "responses": {"200": {"description": "Push device registered"}, "401": {"$ref": "#/components/responses/Error"}, "422": {"$ref": "#/components/responses/Error"}}
      },
      "delete": {
        "summary": "Remove one or all push devices for the current user",
        "requestBody": {"content": {"application/json": {"schema": {"type": "object", "properties": {"token": {"type": "string"}}}}}},
        "responses": {"200": {"description": "Push device removed"}, "401": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/user/jobs.php": {
      "get": {
        "summary": "Paginated processing history",
        "parameters": [
          {"name": "page", "in": "query", "schema": {"type": "integer", "minimum": 1, "default": 1}},
          {"name": "limit", "in": "query", "schema": {"type": "integer", "minimum": 1, "maximum": 50, "default": 20}}
        ],
        "responses": {"200": {"description": "Job list"}, "401": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/tools/index.php": {
      "get": {"summary": "File and AI tool catalog with option schemas", "responses": {"200": {"description": "Tool catalog"}}}
    },
    "/jobs/upload.php": {
      "post": {
        "summary": "Upload files for a tool job",
        "requestBody": {
          "required": true,
          "content": {"multipart/form-data": {"schema": {
            "type": "object",
            "required": ["tool", "files[]"],
            "properties": {
              "tool": {"type": "string", "example": "merge"},
              "files[]": {"type": "array", "items": {"type": "string", "format": "binary"}}
            }
          }}}
        },
        "responses": {"201": {"description": "Uploaded"}, "422": {"$ref": "#/components/responses/Error"}, "429": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/jobs/process.php": {
      "post": {
        "summary": "Process an uploaded job",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {
          "type": "object", "required": ["job_id"],
          "properties": {"job_id": {"type": "string", "minLength": 32, "maxLength": 32}, "options": {"type": "object", "additionalProperties": true}}
        }}}},
        "responses": {"200": {"description": "Processed"}, "409": {"$ref": "#/components/responses/Error"}, "422": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/jobs/status.php": {
      "get": {
        "summary": "Get job status",
        "parameters": [{"name": "id", "in": "query", "required": true, "schema": {"type": "string", "minLength": 32, "maxLength": 32}}],
        "responses": {"200": {"description": "Job status"}, "404": {"$ref": "#/components/responses/Error"}}
      }
    },
    "/jobs/download.php": {
      "get": {
        "summary": "Download a completed output",
        "parameters": [{"name": "id", "in": "query", "required": true, "schema": {"type": "string"}}],
        "responses": {
          "200": {"description": "Output file", "content": {"application/pdf": {}, "application/zip": {}, "image/png": {}, "image/jpeg": {}, "text/plain": {}}},
          "404": {"$ref": "#/components/responses/Error"}
        }
      }
    },
    "/ai/generate.php": {
      "post": {
        "summary": "Generate text with a self-hosted AI tool",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/AiRequest"}}}},
        "responses": {"200": {"description": "Generated text"}, "422": {"$ref": "#/components/responses/Error"}, "429": {"$ref": "#/components/responses/Error"}, "503": {"$ref": "#/components/responses/Error"}}
      }
    }
  },
  "components": {
    "securitySchemes": {
      "mobileBearer": {"type": "http", "scheme": "bearer", "bearerFormat": "PDFPrime mobile access token"}
    },
    "schemas": {
      "RegisterRequest": {
        "type": "object",
        "required": ["name", "email", "password", "password_confirmation", "accepted_terms"],
        "properties": {
          "name": {"type": "string", "minLength": 2, "maxLength": 100},
          "email": {"type": "string", "format": "email", "maxLength": 190},
          "password": {"type": "string", "format": "password", "minLength": 8},
          "password_confirmation": {"type": "string", "format": "password"},
          "accepted_terms": {"type": "boolean"},
          "device_name": {"type": "string", "maxLength": 100}
        }
      },
      "LoginRequest": {
        "type": "object",
        "required": ["email", "password"],
        "properties": {
          "email": {"type": "string", "format": "email"},
          "password": {"type": "string", "format": "password"},
          "device_name": {"type": "string", "maxLength": 100}
        }
      },
      "AiRequest": {
        "type": "object",
        "required": ["tool", "input"],
        "properties": {
          "tool": {"type": "string", "example": "article-writer"},
          "input": {"type": "string", "minLength": 3, "maxLength": 12000},
          "tone": {"type": "string", "enum": ["professional", "friendly", "creative", "persuasive", "simple"]},
          "language": {"type": "string", "enum": ["English", "Hindi", "Hinglish", "Spanish", "French", "German", "Portuguese", "Arabic"]},
          "length": {"type": "string", "enum": ["short", "medium", "long"]}
        }
      },
      "Success": {
        "type": "object",
        "required": ["status", "message", "data"],
        "properties": {
          "status": {"type": "boolean", "example": true},
          "message": {"type": "string", "example": ""},
          "data": {"oneOf": [{"type": "object"}, {"type": "array", "items": {}}]}
        }
      },
      "Error": {
        "type": "object",
        "required": ["status", "message", "data"],
        "properties": {
          "status": {"type": "boolean", "example": false},
          "message": {"type": "string", "example": "Please check the supplied fields."},
          "data": {
            "type": "object",
            "required": ["code", "request_id"],
            "properties": {
              "code": {"type": "string", "example": "validation_failed"},
              "request_id": {"type": "string"},
              "fields": {"type": "object"}
            }
          }
        }
      }
    },
    "responses": {
      "Error": {"description": "Error response", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
    }
  }
}
