openapi: 3.0.0
info:
  title: Client Channel API
  description: API for managing client channels - distribution channels for organizing and categorizing clients
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Channel
    description: Client channel management operations
paths:
  /client-channel:
    get:
      tags:
        - Channel
      summary: Get all client channels
      description: Retrieve a list of all client channels with optional filtering and pagination
      parameters:
        - name: page
          in: query
          description: Page number for pagination
          required: false
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: per_page
          in: query
          description: Number of items per page
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 25
        - name: sort
          in: query
          description: Sort field
          required: false
          schema:
            type: string
        - name: _id
          in: query
          description: Filter by channel ID(s)
          required: false
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
        - name: search
          in: query
          description: Search text for channel name
          required: false
          schema:
            type: string
        - name: name
          in: query
          description: Filter by channel name(s)
          required: false
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
        - name: local_name
          in: query
          description: Filter by local name(s)
          required: false
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
        - name: disabled
          in: query
          description: Filter by disabled status
          required: false
          schema:
            type: boolean
        - name: from_updatedAt
          in: query
          description: Filter channels updated after this timestamp
          required: false
          schema:
            type: integer
            format: int64
        - name: from__id
          in: query
          description: Filter channels with ID greater than this value
          required: false
          schema:
            type: string
        - name: to__id
          in: query
          description: Filter channels with ID less than this value
          required: false
          schema:
            type: string
        - name: sortBy
          in: query
          description: Advanced sorting options
          required: false
          schema:
            type: array
            items:
              type: object
              properties:
                field:
                  type: string
                  enum: ["_id"]
                type:
                  type: string
                  enum: ["asc", "desc"]
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: "#/components/schemas/ChannelSchema"
                  pagination:
                    $ref: "#/components/schemas/PaginationResult"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    post:
      tags:
        - Channel
      summary: Create a new client channel
      description: Create a new client channel
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ChannelCreateBody"
      responses:
        "201":
          description: Channel created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ChannelSchema"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /client-channel/{id}:
    get:
      tags:
        - Channel
      summary: Get a specific client channel
      description: Retrieve a specific client channel by ID
      parameters:
        - name: id
          in: path
          description: Channel ID
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ChannelSchema"
        "404":
          $ref: "#/components/responses/NotFound"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    put:
      tags:
        - Channel
      summary: Update a client channel
      description: Update an existing client channel
      parameters:
        - name: id
          in: path
          description: Channel ID
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ChannelUpdateBody"
      responses:
        "200":
          description: Channel updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ChannelSchema"
        "400":
          $ref: "#/components/responses/BadRequest"
        "404":
          $ref: "#/components/responses/NotFound"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    delete:
      tags:
        - Channel
      summary: Delete a client channel
      description: Delete an existing client channel
      parameters:
        - name: id
          in: path
          description: Channel ID
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Channel deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ChannelSchema"
        "404":
          $ref: "#/components/responses/NotFound"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: Bearer token authentication
  schemas:
    ChannelSchema:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the channel
          example: "60f1b2b3c9e9a12345678901"
        name:
          type: string
          description: Channel name
          example: "Retail Channel"
        local_name:
          type: string
          description: Local/translated name
          example: "قناة التجزئة"
        disabled:
          type: boolean
          description: Whether the channel is disabled
          example: false
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "ch_123", "sync_status": "active" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this channel belongs to
          example: ["company1"]
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
          example: "2023-01-15T10:30:00.000Z"
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
          example: "2023-01-15T10:30:00.000Z"
        __v:
          type: integer
          description: Version key
          example: 0
      required:
        - _id
        - name
        - company_namespace
        - createdAt
        - updatedAt
        - __v
    ChannelCreateBody:
      type: object
      properties:
        name:
          type: string
          description: Channel name (required)
          example: "Retail Channel"
        local_name:
          type: string
          description: Local/translated name
          example: "قناة التجزئة"
        disabled:
          type: boolean
          description: Whether the channel is disabled
          example: false
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "ch_123" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this channel belongs to
          example: ["company1"]
      required:
        - name
    ChannelUpdateBody:
      type: object
      properties:
        name:
          type: string
          description: Channel name
          example: "Updated Retail Channel"
        local_name:
          type: string
          description: Local/translated name
          example: "قناة التجزئة المحدثة"
        disabled:
          type: boolean
          description: Whether the channel is disabled
          example: false
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "ch_123", "sync_status": "updated" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this channel belongs to
          example: ["company1"]
        _id:
          type: string
          description: Channel ID (for internal use)
          example: "60f1b2b3c9e9a12345678901"
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp (for internal use)
          example: "2023-01-15T10:30:00.000Z"
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp (for internal use)
          example: "2023-01-15T10:30:00.000Z"
        __v:
          type: integer
          description: Version key (for internal use)
          example: 0
    PaginationResult:
      type: object
      properties:
        page:
          type: integer
          example: 1
        per_page:
          type: integer
          example: 25
        pre_page:
          type: integer
          example: 0
        next_page:
          type: integer
          example: 2
        total:
          type: integer
          example: 100
        total_page:
          type: integer
          example: 4
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Invalid request parameters"
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Authentication required"
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Channel not found"
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                example: false
              error:
                type: string
                example: "Internal server error"
