{
    "openapi": "3.1.0",
    "info": {
        "title": "SMMFlash API",
        "version": "2.1.0",
        "description": "REST API v2 for token auth, catalog and order management."
    },
    "servers": [
        {
            "url": "https://smmflash.ru/api/v2",
            "description": "API v2 base URL"
        }
    ],
    "tags": [
        {
            "name": "Auth",
            "description": "Token lifecycle"
        },
        {
            "name": "User",
            "description": "Current account information"
        },
        {
            "name": "Services",
            "description": "Catalog operations"
        },
        {
            "name": "Orders",
            "description": "Order creation and tracking"
        }
    ],
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "bearerFormat": "API token"
            }
        },
        "schemas": {
            "V2Meta": {
                "type": "object",
                "required": [
                    "api_version",
                    "request_id",
                    "timestamp"
                ],
                "properties": {
                    "api_version": {
                        "type": "string",
                        "example": "v2"
                    },
                    "request_id": {
                        "type": "string",
                        "example": "a1b2c3d4e5f67890"
                    },
                    "timestamp": {
                        "type": "string",
                        "format": "date-time"
                    }
                }
            },
            "V2ErrorObject": {
                "type": "object",
                "required": [
                    "code",
                    "message"
                ],
                "properties": {
                    "code": {
                        "type": "string",
                        "example": "validation_error"
                    },
                    "message": {
                        "type": "string",
                        "example": "Invalid input"
                    },
                    "details": {
                        "type": "object",
                        "additionalProperties": true
                    }
                }
            },
            "V2ErrorResponse": {
                "type": "object",
                "required": [
                    "success",
                    "error",
                    "meta"
                ],
                "properties": {
                    "success": {
                        "type": "boolean",
                        "example": false
                    },
                    "error": {
                        "$ref": "#/components/schemas/V2ErrorObject"
                    },
                    "meta": {
                        "$ref": "#/components/schemas/V2Meta"
                    }
                }
            },
            "V2SuccessGeneric": {
                "type": "object",
                "required": [
                    "success",
                    "data",
                    "meta"
                ],
                "properties": {
                    "success": {
                        "type": "boolean",
                        "example": true
                    },
                    "data": {
                        "type": "object",
                        "additionalProperties": true
                    },
                    "meta": {
                        "$ref": "#/components/schemas/V2Meta"
                    }
                }
            },
            "TokenIssueRequest": {
                "type": "object",
                "required": [
                    "email",
                    "password"
                ],
                "properties": {
                    "email": {
                        "type": "string",
                        "format": "email",
                        "example": "you@example.com"
                    },
                    "password": {
                        "type": "string",
                        "example": "your_password"
                    },
                    "token_name": {
                        "type": "string",
                        "maxLength": 120,
                        "example": "Server integration"
                    },
                    "ttl_days": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 365,
                        "example": 30
                    }
                }
            },
            "CreateOrderRequest": {
                "type": "object",
                "required": [
                    "service_id",
                    "link",
                    "quantity"
                ],
                "properties": {
                    "service_id": {
                        "type": "integer",
                        "example": 9
                    },
                    "link": {
                        "type": "string",
                        "example": "https://t.me/your_channel/123"
                    },
                    "quantity": {
                        "type": "integer",
                        "example": 1000
                    }
                }
            },
            "V2TokenIssueResponse": {
                "type": "object",
                "required": [
                    "success",
                    "data",
                    "meta"
                ],
                "properties": {
                    "success": {
                        "type": "boolean",
                        "example": true
                    },
                    "data": {
                        "type": "object",
                        "properties": {
                            "token_type": {
                                "type": "string",
                                "example": "Bearer"
                            },
                            "access_token": {
                                "type": "string",
                                "example": "smf_..."
                            },
                            "expires_at": {
                                "type": "string",
                                "format": "date-time"
                            },
                            "user": {
                                "type": "object"
                            }
                        }
                    },
                    "meta": {
                        "$ref": "#/components/schemas/V2Meta"
                    }
                }
            }
        }
    },
    "paths": {
        "/auth/token": {
            "post": {
                "tags": [
                    "Auth"
                ],
                "summary": "Issue a new API token",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/TokenIssueRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Token issued",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2TokenIssueResponse"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/auth/revoke": {
            "post": {
                "tags": [
                    "Auth"
                ],
                "summary": "Revoke current token",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Token revoked",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/me": {
            "get": {
                "tags": [
                    "User"
                ],
                "summary": "Current user profile",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "responses": {
                    "200": {
                        "description": "User profile",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/services": {
            "get": {
                "tags": [
                    "Services"
                ],
                "summary": "List active services",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": [
                    {
                        "in": "query",
                        "name": "q",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "in": "query",
                        "name": "cat",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "in": "query",
                        "name": "sub",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "in": "query",
                        "name": "sort",
                        "schema": {
                            "type": "string",
                            "example": "rate_asc"
                        }
                    },
                    {
                        "in": "query",
                        "name": "page",
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    },
                    {
                        "in": "query",
                        "name": "per_page",
                        "schema": {
                            "type": "integer",
                            "default": 20,
                            "maximum": 100
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Service list",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/services/{serviceId}": {
            "get": {
                "tags": [
                    "Services"
                ],
                "summary": "Get one service",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": [
                    {
                        "in": "path",
                        "name": "serviceId",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Service details",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders": {
            "get": {
                "tags": [
                    "Orders"
                ],
                "summary": "List current user orders",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": [
                    {
                        "in": "query",
                        "name": "status",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "in": "query",
                        "name": "page",
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    },
                    {
                        "in": "query",
                        "name": "per_page",
                        "schema": {
                            "type": "integer",
                            "default": 20,
                            "maximum": 100
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Orders list",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "tags": [
                    "Orders"
                ],
                "summary": "Create order",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/CreateOrderRequest"
                            }
                        },
                        "application/x-www-form-urlencoded": {
                            "schema": {
                                "$ref": "#/components/schemas/CreateOrderRequest"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Order created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation error",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/orders/{orderId}": {
            "get": {
                "tags": [
                    "Orders"
                ],
                "summary": "Get one order",
                "security": [
                    {
                        "bearerAuth": []
                    }
                ],
                "parameters": [
                    {
                        "in": "path",
                        "name": "orderId",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Order details",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2SuccessGeneric"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/V2ErrorResponse"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}