{
  "openapi": "3.0.3",
  "info": {
    "title": "SoftStore Reseller API",
    "version": "2.0.0"
  },
  "servers": [
    {
      "url": "https://api.softstore.app/api/v2"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "required": [
          "ok",
          "code",
          "message"
        ],
        "properties": {
          "ok": {
            "type": "boolean",
            "example": false
          },
          "code": {
            "type": "string",
            "example": "insufficient_balance"
          },
          "message": {
            "type": "string",
            "example": "Insufficient balance"
          },
          "http_status": {
            "type": "integer",
            "example": 409
          },
          "error": {
            "type": "object",
            "required": [
              "code"
            ],
            "properties": {
              "code": {
                "type": "string",
                "example": "insufficient_balance"
              },
              "details": {
                "type": "object",
                "additionalProperties": true,
                "example": {}
              }
            }
          }
        }
      },
      "PaginationMeta": {
        "type": "object",
        "properties": {
          "page": {
            "type": "integer"
          },
          "limit": {
            "type": "integer"
          },
          "total": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          }
        }
      },
      "ProductSummary": {
        "type": "object",
        "properties": {
          "id_product": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "img": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "price": {
            "type": "integer"
          },
          "currency": {
            "type": "string"
          },
          "count": {
            "type": "integer"
          },
          "available": {
            "type": "boolean"
          },
          "seller_id": {
            "type": "integer"
          },
          "category_id": {
            "type": "integer"
          },
          "discount": {
            "type": "integer"
          },
          "opt_price": {
            "type": "string"
          },
          "opt_count": {
            "type": "string"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id_order": {
            "type": "string"
          },
          "id_product": {
            "type": "string"
          },
          "id_seller": {
            "type": "integer"
          },
          "status_order": {
            "type": "string"
          },
          "amount": {
            "type": "integer"
          },
          "count": {
            "type": "integer"
          },
          "h2h": {
            "type": "integer"
          }
        }
      },
      "ChatMessage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "type_user": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "data_create": {
            "type": "string"
          },
          "time_create": {
            "type": "string"
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/auth/api-key/create": {
      "post": {
        "security": [],
        "summary": "Exchange API key for Bearer token",
        "responses": {
          "200": {
            "description": "Token"
          }
        }
      }
    },
    "/balance": {
      "get": {
        "summary": "Balance",
        "responses": {
          "200": {
            "description": "Balance"
          }
        }
      }
    },
    "/search": {
      "get": {
        "summary": "Search products",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "seller_id",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Product list"
          }
        }
      }
    },
    "/products/{seller_id}": {
      "get": {
        "summary": "Seller products",
        "parameters": [
          {
            "name": "seller_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Product list"
          }
        }
      }
    },
    "/product/{product_id}": {
      "get": {
        "summary": "Product details",
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Product"
          }
        }
      }
    },
    "/buy": {
      "post": {
        "summary": "Buy product",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "product_id",
                  "quantity"
                ],
                "properties": {
                  "product_id": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "integer"
                  },
                  "comment": {
                    "type": "string",
                    "maxLength": 200,
                    "description": "Buyer activation data. Required when product comment_status is enabled. HTML/script/control chars are rejected. Configured product regex must match the complete value or 422 comment_regex_mismatch is returned.",
                    "example": "buyer_login@example.com"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Order created"
          },
          "409": {
            "description": "Validation conflict"
          },
          "422": {
            "description": "Invalid comment or comment_regex_mismatch"
          }
        },
        "description": "Buy product. Comment is stored and forwarded only after required and regex validation succeeds."
      }
    },
    "/history": {
      "get": {
        "summary": "Order history",
        "responses": {
          "200": {
            "description": "Orders"
          }
        }
      }
    },
    "/order/{order_id}": {
      "get": {
        "summary": "Order details",
        "parameters": [
          {
            "name": "order_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Order"
          }
        }
      }
    },
    "/favorites": {
      "get": {
        "summary": "Favorites",
        "responses": {
          "200": {
            "description": "Favorites"
          }
        }
      },
      "post": {
        "summary": "Update favorite",
        "responses": {
          "200": {
            "description": "Favorite state"
          }
        }
      }
    },
    "/comment/{product_id}": {
      "get": {
        "summary": "Product comments",
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Comments"
          }
        }
      }
    },
    "/chat/{chat_id}": {
      "get": {
        "summary": "Read chat",
        "parameters": [
          {
            "name": "chat_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chat"
          }
        }
      },
      "post": {
        "summary": "Send chat message",
        "responses": {
          "200": {
            "description": "Sent"
          }
        }
      }
    },
    "/dispute": {
      "post": {
        "summary": "Open or close dispute",
        "responses": {
          "200": {
            "description": "Dispute state"
          }
        }
      }
    },
    "/gift": {
      "post": {
        "tags": [
          "Reseller"
        ],
        "summary": "Create Gift",
        "description": "Creates a paid H2H Gift order from reseller balance and returns a Gift activation code. Product must have gift_available=1. First release supports quantity/count=1 only.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "product_id"
                ],
                "properties": {
                  "product_id": {
                    "type": "string",
                    "example": "PRODUCT_ID"
                  },
                  "quantity": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1,
                    "default": 1
                  },
                  "count": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 1,
                    "default": 1
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Gift created",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/SuccessResponse"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "order_id": {
                              "type": "string"
                            },
                            "product_id": {
                              "type": "string"
                            },
                            "quantity": {
                              "type": "integer",
                              "example": 1
                            },
                            "total": {
                              "type": "integer",
                              "example": 999
                            },
                            "currency": {
                              "type": "string",
                              "example": "RUB"
                            },
                            "h2h": {
                              "type": "integer",
                              "example": 1
                            },
                            "gift": {
                              "type": "integer",
                              "example": 1
                            },
                            "gift_code": {
                              "type": "string",
                              "example": "GIFT-0123456789ABCDEF"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Gift unavailable, insufficient stock or insufficient balance",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "422": {
            "description": "Validation error, including count > 1",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  }
}
