openapi: 3.1.0
info:
  title: BloomCore API - Public catalog
  version: 1.0.0
  description: |
    Read-only каталог конкретного магазина: публичные категории, товары и услуги,
    рецепты с вариантами и готовые букеты. Сервер применяет те же правила публикации,
    видимости родительских категорий, цен и остатков, что и интернет-магазин.

    Все CRM `id` и `*_id` являются UUID-строками. Внутренние bigint ID, закупочные
    цены, себестоимость, маржа, поставщики, партии и служебные metadata не выдаются.
    Для всех методов необходимы scope `catalog.view`, CRM-право `products.view`
    на магазин текущего поддомена и активная подписка на публичный API.
servers:
  - url: https://{tenant_subdomain}.crm.flowers/api/v1
    variables:
      tenant_subdomain:
        default: florio
        description: Поддомен магазина, определяющий цены, остатки и права доступа.
security:
  - bearerAuth: []
paths:
  /catalog/categories:
    get:
      operationId: listPublicCatalogCategories
      summary: Получить публичные категории
      description: |
        Без `parent_id` возвращает все доступные категории плоским списком.
        С `parent_id` возвращает только непосредственных публичных потомков.
        Скрытая или неактивная родительская категория скрывает всю ветку.
      parameters:
        - $ref: '#/components/parameters/ParentCategoryId'
      responses:
        '200':
          description: Категории публичного каталога текущего магазина.
          headers:
            Cache-Control:
              schema: {type: string}
              description: Всегда `private, no-store, max-age=0`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CategoryListSuccess'
              example:
                success: true
                data:
                  items:
                    - id: 019f8000-1000-7001-8000-000000000001
                      parent_id: null
                      name: Цветы
                      color: '#E11D48'
                      icon: flower
                      root_key: flowers
                      depth: 0
                      children_count: 2
                  count: 1
                request_id: 019f8000-1000-7002-8000-000000000002
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/ValidationFailed'
  /catalog/products:
    get:
      operationId: listPublicCatalogProducts
      summary: Получить товары и услуги
      description: |
        Возвращает только активные позиции, опубликованные для текущего магазина.
        Если для позиции включено скрытие при нулевом остатке, такая позиция не
        возвращается. Цена и доступный остаток рассчитываются для текущего магазина.
      parameters:
        - $ref: '#/components/parameters/Search'
        - $ref: '#/components/parameters/CategoryId'
        - name: type
          in: query
          required: false
          schema:
            type: string
            enum: [flower, product, consumable, gift, certificate, service]
        - $ref: '#/components/parameters/Page'
        - $ref: '#/components/parameters/PerPage'
      responses:
        '200':
          description: Страница товаров и услуг.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProductListSuccess'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/ValidationFailed'
  /catalog/recipes:
    get:
      operationId: listPublicCatalogRecipes
      summary: Получить рецепты и варианты
      description: |
        Возвращает опубликованные рецепты минимум с одним активным для магазина
        вариантом. Цена, медиа и состав относятся к варианту. Если у варианта нет
        собственных медиа, используется медиа рецепта. Состав возвращается только
        при разрешённом владельцем показе состава.
      parameters:
        - $ref: '#/components/parameters/Search'
        - $ref: '#/components/parameters/CategoryId'
        - name: available
          in: query
          required: false
          description: Публичный каталог поддерживает только доступные позиции; `false` возвращает пустую страницу.
          schema: {type: boolean, default: true}
        - $ref: '#/components/parameters/PriceFrom'
        - $ref: '#/components/parameters/PriceTo'
        - $ref: '#/components/parameters/Page'
        - $ref: '#/components/parameters/PerPage'
      responses:
        '200':
          description: Страница рецептов с вариантами.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecipeListSuccess'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/ValidationFailed'
  /catalog/bouquets:
    get:
      operationId: listPublicReadyBouquets
      summary: Получить готовые букеты
      description: |
        Возвращает только опубликованные готовые букеты текущего магазина со статусом
        `available` и положительным остатком. Забронированные, проданные, списанные
        и архивные букеты не выдаются.
      parameters:
        - $ref: '#/components/parameters/Search'
        - $ref: '#/components/parameters/CategoryId'
        - $ref: '#/components/parameters/PriceFrom'
        - $ref: '#/components/parameters/PriceTo'
        - $ref: '#/components/parameters/Page'
        - $ref: '#/components/parameters/PerPage'
      responses:
        '200':
          description: Страница готовых букетов.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReadyBouquetListSuccess'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/ValidationFailed'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: BloomCore API token
  parameters:
    Search:
      name: search
      in: query
      required: false
      description: Поиск по названию и описанию, не более 255 символов.
      schema: {type: string, maxLength: 255}
    CategoryId:
      name: category_id
      in: query
      required: false
      description: UUID публичной категории; поиск включает всё доступное поддерево.
      schema: {type: string, format: uuid}
    ParentCategoryId:
      name: parent_id
      in: query
      required: false
      description: UUID публичной родительской категории.
      schema: {type: string, format: uuid}
    PriceFrom:
      name: price_from
      in: query
      required: false
      schema: {type: number, minimum: 0, maximum: 999999999.99}
    PriceTo:
      name: price_to
      in: query
      required: false
      description: Должно быть не меньше `price_from`.
      schema: {type: number, minimum: 0, maximum: 999999999.99}
    Page:
      name: page
      in: query
      required: false
      schema: {type: integer, minimum: 1, maximum: 100000, default: 1}
    PerPage:
      name: per_page
      in: query
      required: false
      schema: {type: integer, minimum: 1, maximum: 100, default: 25}
  responses:
    Unauthorized:
      description: API-токен отсутствует, истёк или отозван.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/ErrorEnvelope'}
    Forbidden:
      description: Не совпал tenant/store, scope `catalog.view`, CRM-право или подписка.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/ErrorEnvelope'}
    ValidationFailed:
      description: Передан неизвестный фильтр, неверный UUID или значение вне ограничений.
      content:
        application/json:
          schema: {$ref: '#/components/schemas/ErrorEnvelope'}
  schemas:
    Category:
      type: object
      additionalProperties: false
      required: [id, parent_id, name, color, icon, root_key, depth, children_count]
      properties:
        id:
          type: string
          format: uuid
        parent_id:
          type: [string, 'null']
          format: uuid
        name: {type: string}
        color: {type: string, pattern: '^#[0-9A-Fa-f]{6}$'}
        icon: {type: string}
        root_key: {type: [string, 'null']}
        depth: {type: integer, minimum: 0}
        children_count: {type: integer, minimum: 0}
    CategoryReference:
      type: object
      additionalProperties: false
      required: [id, name, color]
      properties:
        id:
          type: string
          format: uuid
        name: {type: string}
        color: {type: string, pattern: '^#[0-9A-Fa-f]{6}$'}
    MediaItem:
      type: object
      additionalProperties: false
      required: [type, url, is_primary, mime_type]
      properties:
        type: {type: string, enum: [image, video]}
        url: {type: string, format: uri}
        is_primary: {type: boolean}
        mime_type: {type: string}
    Availability:
      type: object
      additionalProperties: false
      required: [available, is_stock_tracked, qty_available, unit, allow_fractional_quantity]
      properties:
        available: {type: boolean}
        is_stock_tracked: {type: boolean}
        qty_available:
          type: [string, 'null']
          description: Десятичная строка без лишних нулей; `null` для неучитываемой позиции.
        unit: {type: [string, 'null']}
        allow_fractional_quantity: {type: boolean}
    Product:
      type: object
      additionalProperties: false
      required:
        - id
        - type
        - name
        - description
        - category
        - regular_price
        - discount_price
        - effective_price
        - currency_code
        - media
        - availability
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        type: {type: string, enum: [flower, product, consumable, gift, certificate, service]}
        name: {type: string}
        description: {type: [string, 'null']}
        category:
          oneOf:
            - {$ref: '#/components/schemas/CategoryReference'}
            - {type: 'null'}
        regular_price: {$ref: '#/components/schemas/Money'}
        discount_price:
          oneOf:
            - {$ref: '#/components/schemas/Money'}
            - {type: 'null'}
        effective_price: {$ref: '#/components/schemas/Money'}
        currency_code: {type: string, pattern: '^[A-Z]{3}$'}
        media:
          type: array
          items: {$ref: '#/components/schemas/MediaItem'}
        availability: {$ref: '#/components/schemas/Availability'}
        updated_at: {type: [string, 'null'], format: date-time}
    RecipeCompositionAlternative:
      type: object
      additionalProperties: false
      required: [product_id, name, qty, priority]
      properties:
        product_id:
          type: [string, 'null']
          format: uuid
        name: {type: string}
        qty: {type: string}
        priority: {type: integer, minimum: 0}
    RecipeCompositionItem:
      type: object
      additionalProperties: false
      required: [product_id, name, qty, unit, role, is_required, alternatives]
      properties:
        product_id:
          type: [string, 'null']
          format: uuid
        name: {type: string}
        qty: {type: string}
        unit: {type: [string, 'null']}
        role: {type: [string, 'null']}
        is_required: {type: boolean}
        alternatives:
          type: array
          items: {$ref: '#/components/schemas/RecipeCompositionAlternative'}
    RecipeVariant:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - size
        - dimensions
        - regular_price
        - discount_price
        - effective_price
        - currency_code
        - media_source
        - media
        - composition
      properties:
        id:
          type: string
          format: uuid
        name: {type: string}
        size: {type: [string, 'null']}
        dimensions: {$ref: '#/components/schemas/Dimensions'}
        regular_price: {$ref: '#/components/schemas/Money'}
        discount_price:
          oneOf:
            - {$ref: '#/components/schemas/Money'}
            - {type: 'null'}
        effective_price: {$ref: '#/components/schemas/Money'}
        currency_code: {type: string, pattern: '^[A-Z]{3}$'}
        media_source: {type: string, enum: [variant, recipe]}
        media:
          type: array
          items: {$ref: '#/components/schemas/MediaItem'}
        composition:
          type: array
          items: {$ref: '#/components/schemas/RecipeCompositionItem'}
    Recipe:
      type: object
      additionalProperties: false
      required: [id, name, description, category, show_composition, media, variants, updated_at]
      properties:
        id:
          type: string
          format: uuid
        name: {type: string}
        description: {type: [string, 'null']}
        category:
          oneOf:
            - {$ref: '#/components/schemas/CategoryReference'}
            - {type: 'null'}
        show_composition: {type: boolean}
        media:
          type: array
          items: {$ref: '#/components/schemas/MediaItem'}
        variants:
          type: array
          minItems: 1
          items: {$ref: '#/components/schemas/RecipeVariant'}
        updated_at: {type: [string, 'null'], format: date-time}
    ReadyBouquetCompositionItem:
      type: object
      additionalProperties: false
      required: [product_id, name, qty, unit, is_substitution]
      properties:
        product_id:
          type: [string, 'null']
          format: uuid
        name: {type: string}
        qty: {type: string}
        unit: {type: [string, 'null']}
        is_substitution: {type: boolean}
    PriceAdjustments:
      type: object
      additionalProperties: false
      required: [markup_percent, markup_amount, discount_percent, discount_amount]
      properties:
        markup_percent: {type: [string, 'null']}
        markup_amount:
          oneOf:
            - {$ref: '#/components/schemas/Money'}
            - {type: 'null'}
        discount_percent: {type: [string, 'null']}
        discount_amount:
          oneOf:
            - {$ref: '#/components/schemas/Money'}
            - {type: 'null'}
    ReadyBouquet:
      type: object
      additionalProperties: false
      required:
        - id
        - store_id
        - name
        - description
        - category
        - media
        - composition_price
        - regular_price
        - discount_price
        - effective_price
        - currency_code
        - price_adjustments
        - qty_available
        - size
        - dimensions
        - expires_at
        - composition
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        store_id:
          type: string
          format: uuid
        name: {type: string}
        description: {type: [string, 'null']}
        category:
          oneOf:
            - {$ref: '#/components/schemas/CategoryReference'}
            - {type: 'null'}
        media:
          type: array
          items: {$ref: '#/components/schemas/MediaItem'}
        composition_price: {$ref: '#/components/schemas/Money'}
        regular_price: {$ref: '#/components/schemas/Money'}
        discount_price:
          oneOf:
            - {$ref: '#/components/schemas/Money'}
            - {type: 'null'}
        effective_price: {$ref: '#/components/schemas/Money'}
        currency_code: {type: string, pattern: '^[A-Z]{3}$'}
        price_adjustments: {$ref: '#/components/schemas/PriceAdjustments'}
        qty_available: {type: string}
        size: {type: [string, 'null']}
        dimensions: {$ref: '#/components/schemas/Dimensions'}
        expires_at: {type: [string, 'null'], format: date-time}
        composition:
          type: array
          items: {$ref: '#/components/schemas/ReadyBouquetCompositionItem'}
        updated_at: {type: [string, 'null'], format: date-time}
    Dimensions:
      type: object
      additionalProperties: false
      required: [width_cm, height_cm]
      properties:
        width_cm: {type: [string, 'null']}
        height_cm: {type: [string, 'null']}
    Money:
      type: string
      pattern: '^[0-9]+\.[0-9]{2}$'
      example: '3500.00'
    Pagination:
      type: object
      additionalProperties: false
      required: [total, per_page, current_page, last_page]
      properties:
        total: {type: integer, minimum: 0}
        per_page: {type: integer, minimum: 1, maximum: 100}
        current_page: {type: integer, minimum: 1}
        last_page: {type: integer, minimum: 1}
    CategoryListData:
      type: object
      additionalProperties: false
      required: [items, count]
      properties:
        items:
          type: array
          items: {$ref: '#/components/schemas/Category'}
        count: {type: integer, minimum: 0}
    ProductListData:
      type: object
      additionalProperties: false
      required: [items, meta]
      properties:
        items:
          type: array
          items: {$ref: '#/components/schemas/Product'}
        meta: {$ref: '#/components/schemas/Pagination'}
    RecipeListData:
      type: object
      additionalProperties: false
      required: [items, meta]
      properties:
        items:
          type: array
          items: {$ref: '#/components/schemas/Recipe'}
        meta: {$ref: '#/components/schemas/Pagination'}
    ReadyBouquetListData:
      type: object
      additionalProperties: false
      required: [items, meta]
      properties:
        items:
          type: array
          items: {$ref: '#/components/schemas/ReadyBouquet'}
        meta: {$ref: '#/components/schemas/Pagination'}
    CategoryListSuccess:
      type: object
      additionalProperties: false
      required: [success, data, request_id]
      properties:
        success: {type: boolean, const: true}
        data: {$ref: '#/components/schemas/CategoryListData'}
        request_id:
          type: string
          format: uuid
    ProductListSuccess:
      type: object
      additionalProperties: false
      required: [success, data, request_id]
      properties:
        success: {type: boolean, const: true}
        data: {$ref: '#/components/schemas/ProductListData'}
        request_id:
          type: string
          format: uuid
    RecipeListSuccess:
      type: object
      additionalProperties: false
      required: [success, data, request_id]
      properties:
        success: {type: boolean, const: true}
        data: {$ref: '#/components/schemas/RecipeListData'}
        request_id:
          type: string
          format: uuid
    ReadyBouquetListSuccess:
      type: object
      additionalProperties: false
      required: [success, data, request_id]
      properties:
        success: {type: boolean, const: true}
        data: {$ref: '#/components/schemas/ReadyBouquetListData'}
        request_id:
          type: string
          format: uuid
    ErrorObject:
      type: object
      additionalProperties: true
      required: [code, message]
      properties:
        code: {type: string}
        message: {type: string}
        details: {type: object}
    ErrorEnvelope:
      type: object
      additionalProperties: false
      required: [success, error, request_id]
      properties:
        success: {type: boolean, const: false}
        error: {$ref: '#/components/schemas/ErrorObject'}
        request_id:
          type: string
          format: uuid
