openapi: 3.0.3
info:
  title: MenuBino Integration API
  version: 1.0.0
  description: API همگام‌سازی منو؛ فقط برای اشتراک فعال Pro
servers:
  - url: https://api.menubino.ir/api/integrations/v1
security:
  - ApiKey: []
paths:
  /categories:
    get:
      summary: فهرست دسته‌ها
      responses:
        '200':
          description: موفق
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Category' } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /products:
    get:
      summary: فهرست محصولات
      parameters:
        - in: query
          name: updatedSinceUtc
          schema: { type: string, format: date-time }
      responses:
        '200':
          description: موفق
          content:
            application/json:
              schema: { type: array, items: { $ref: '#/components/schemas/Product' } }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
  /products/{productId}:
    patch:
      summary: ویرایش قیمت، توضیح یا تصویر
      parameters:
        - in: path
          name: productId
          required: true
          schema: { type: string, format: uuid }
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/ProductPatch' }
      responses:
        '200':
          description: موفق
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Product' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Invalid' }
  /products/batch:
    post:
      summary: ویرایش حداکثر ۱۰۰ محصول
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [items]
              properties:
                items:
                  type: array
                  minItems: 1
                  maxItems: 100
                  items:
                    allOf:
                      - type: object
                        required: [productId]
                        properties: { productId: { type: string, format: uuid } }
                      - $ref: '#/components/schemas/ProductPatch'
      responses:
        '200': { description: نتیجه جداگانه هر آیتم }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
        '422': { $ref: '#/components/responses/Invalid' }
  /media:
    post:
      summary: آپلود تصویر محصول
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [file]
              properties: { file: { type: string, format: binary } }
      responses:
        '201':
          description: رسانه ساخته شد
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Media' }
        '401': { $ref: '#/components/responses/Unauthorized' }
        '403': { $ref: '#/components/responses/Forbidden' }
        '409': { $ref: '#/components/responses/Conflict' }
        '413': { $ref: '#/components/responses/Invalid' }
        '422': { $ref: '#/components/responses/Invalid' }
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-Api-Key
  parameters:
    IdempotencyKey:
      in: header
      name: Idempotency-Key
      required: true
      schema: { type: string, maxLength: 128 }
  schemas:
    Category:
      type: object
      required: [id, name, sortOrder, isActive, version, updatedAtUtc]
      properties:
        id: { type: string, format: uuid }
        name: { type: string }
        sortOrder: { type: integer }
        isActive: { type: boolean }
        version: { type: integer }
        updatedAtUtc: { type: string, format: date-time }
    Product:
      type: object
      required: [id, name, priceToman, status, version, updatedAtUtc]
      properties:
        id: { type: string, format: uuid }
        externalId: { type: string, nullable: true }
        categoryId: { type: string, format: uuid, nullable: true }
        name: { type: string }
        priceToman: { type: integer, format: int64 }
        description: { type: string, nullable: true }
        mediaId: { type: string, format: uuid, nullable: true }
        imageUrl: { type: string, nullable: true }
        status: { type: string, enum: [Available, Unavailable, Hidden] }
        version: { type: integer }
        updatedAtUtc: { type: string, format: date-time }
    ProductPatch:
      type: object
      required: [expectedVersion]
      properties:
        expectedVersion: { type: integer, minimum: 0 }
        priceToman: { type: integer, format: int64, minimum: 1 }
        description: { type: string, maxLength: 2000, nullable: true }
        mediaId: { type: string, format: uuid, nullable: true }
    Media:
      type: object
      required: [id, url, thumbnailUrl, contentType, width, height, createdAtUtc]
      properties:
        id: { type: string, format: uuid }
        url: { type: string }
        thumbnailUrl: { type: string }
        contentType: { type: string, example: image/webp }
        width: { type: integer }
        height: { type: integer }
        createdAtUtc: { type: string, format: date-time }
    Problem:
      type: object
      properties:
        status: { type: integer }
        code: { type: string }
        title: { type: string }
        detail: { type: string }
        traceId: { type: string }
  responses:
    Unauthorized:
      description: کلید API نامعتبر است
      content: { application/problem+json: { schema: { $ref: '#/components/schemas/Problem' } } }
    Forbidden:
      description: scope یا اشتراک Pro کافی نیست
      content: { application/problem+json: { schema: { $ref: '#/components/schemas/Problem' } } }
    Conflict:
      description: تعارض نسخه یا idempotency
      content: { application/problem+json: { schema: { $ref: '#/components/schemas/Problem' } } }
    Invalid:
      description: ورودی نامعتبر
      content: { application/problem+json: { schema: { $ref: '#/components/schemas/Problem' } } }
