openapi: 3.0.0
info:
  title: Client Contact API
  description: API for managing client contacts - individual contact persons associated with clients
  version: 1.0.0
servers:
  - url: https://api.repzo.me/v1
    description: Production server
security:
  - ApiKeyAuth: []
tags:
  - name: Client Contact
    description: Client contact management operations
paths:
  /client-contact:
    get:
      tags:
        - Client Contact
      summary: Get all client contacts
      description: Retrieve a list of all client contacts 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 contact ID(s)
          required: false
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
        - name: search
          in: query
          description: Search text for contact name
          required: false
          schema:
            type: string
        - name: name
          in: query
          description: Filter by contact name(s)
          required: false
          schema:
            oneOf:
              - type: string
              - type: array
                items:
                  type: string
        - name: from_updatedAt
          in: query
          description: Filter contacts updated after this timestamp
          required: false
          schema:
            type: integer
            format: int64
        - name: to_updatedAt
          in: query
          description: Filter contacts updated before this timestamp
          required: false
          schema:
            type: integer
            format: int64
        - name: from__id
          in: query
          description: Filter contacts with ID greater than this value
          required: false
          schema:
            type: string
        - name: to__id
          in: query
          description: Filter contacts 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/ClientContactSchema"
                  pagination:
                    $ref: "#/components/schemas/PaginationResult"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    post:
      tags:
        - Client Contact
      summary: Create a new client contact
      description: Create a new client contact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ClientContactCreateBody"
      responses:
        "201":
          description: Client contact created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientContactSchema"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
  /client-contact/{id}:
    get:
      tags:
        - Client Contact
      summary: Get a specific client contact
      description: Retrieve a specific client contact by ID
      parameters:
        - name: id
          in: path
          description: Client contact 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/ClientContactSchema"
        "404":
          $ref: "#/components/responses/NotFound"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    put:
      tags:
        - Client Contact
      summary: Update a client contact
      description: Update an existing client contact
      parameters:
        - name: id
          in: path
          description: Client contact ID
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ClientContactUpdateBody"
      responses:
        "200":
          description: Client contact updated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientContactSchema"
        "400":
          $ref: "#/components/responses/BadRequest"
        "404":
          $ref: "#/components/responses/NotFound"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalServerError"
    delete:
      tags:
        - Client Contact
      summary: Delete a client contact
      description: Delete an existing client contact
      parameters:
        - name: id
          in: path
          description: Client contact ID
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Client contact deleted successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: "#/components/schemas/ClientContactSchema"
        "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:
    ClientContactSchema:
      type: object
      properties:
        _id:
          type: string
          description: Unique identifier for the client contact
          example: "60f1b2b3c9e9a12345678901"
        creator:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who created this contact
        editor:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who last edited this contact
        name:
          type: string
          description: Contact name
          example: "John Smith"
        local_name:
          type: string
          description: Local/translated name
          example: "جون سميث"
        phone1:
          type: string
          description: Primary phone number
          example: "+1234567890"
        phone2:
          type: string
          description: Secondary phone number
          example: "+1234567891"
        email:
          type: string
          format: email
          description: Email address
          example: "john.smith@example.com"
        title:
          type: string
          description: Job title or position
          example: "Sales Manager"
        extra_info:
          type: string
          description: Additional information about the contact
          example: "Primary contact for technical issues"
        disabled:
          type: boolean
          description: Whether the contact is disabled
          example: false
        media:
          type: array
          items:
            type: string
          description: Array of media file URLs
          example: ["https://example.com/photo1.jpg"]
        cover_photo:
          type: string
          description: Cover photo URL
          example: "https://example.com/cover.jpg"
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "contact_123", "sync_status": "active" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this contact 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
        - creator
        - name
        - company_namespace
        - createdAt
        - updatedAt
        - __v
    ClientContactCreateBody:
      type: object
      properties:
        name:
          type: string
          description: Contact name (required)
          example: "John Smith"
        creator:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who created this contact
        editor:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who last edited this contact
        local_name:
          type: string
          description: Local/translated name
          example: "جون سميث"
        phone1:
          type: string
          description: Primary phone number
          example: "+1234567890"
        phone2:
          type: string
          description: Secondary phone number
          example: "+1234567891"
        email:
          type: string
          format: email
          description: Email address
          example: "john.smith@example.com"
        title:
          type: string
          description: Job title or position
          example: "Sales Manager"
        extra_info:
          type: string
          description: Additional information about the contact
          example: "Primary contact for technical issues"
        disabled:
          type: boolean
          description: Whether the contact is disabled
          example: false
        media:
          type: array
          items:
            type: string
          description: Array of media file URLs
          example: ["https://example.com/photo1.jpg"]
        cover_photo:
          type: string
          description: Cover photo URL
          example: "https://example.com/cover.jpg"
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "contact_123" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this contact belongs to
          example: ["company1"]
      required:
        - name
    ClientContactUpdateBody:
      type: object
      properties:
        name:
          type: string
          description: Contact name
          example: "John Smith Updated"
        creator:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who created this contact
        editor:
          oneOf:
            - $ref: "#/components/schemas/AdminCreator"
            - $ref: "#/components/schemas/RepCreator"
            - $ref: "#/components/schemas/ClientCreator"
          description: User who last edited this contact
        local_name:
          type: string
          description: Local/translated name
          example: "جون سميث محدث"
        phone1:
          type: string
          description: Primary phone number
          example: "+1234567890"
        phone2:
          type: string
          description: Secondary phone number
          example: "+1234567891"
        email:
          type: string
          format: email
          description: Email address
          example: "john.smith.updated@example.com"
        title:
          type: string
          description: Job title or position
          example: "Senior Sales Manager"
        extra_info:
          type: string
          description: Additional information about the contact
          example: "Primary contact for technical issues - updated"
        disabled:
          type: boolean
          description: Whether the contact is disabled
          example: false
        media:
          type: array
          items:
            type: string
          description: Array of media file URLs
          example:
            ["https://example.com/photo1.jpg", "https://example.com/photo2.jpg"]
        cover_photo:
          type: string
          description: Cover photo URL
          example: "https://example.com/cover-updated.jpg"
        integration_meta:
          type: object
          additionalProperties: true
          description: Metadata for third-party integrations
          example: { "external_id": "contact_123", "sync_status": "updated" }
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces this contact belongs to
          example: ["company1"]
        _id:
          type: string
          description: Contact 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
    AdminCreator:
      type: object
      properties:
        _id:
          type: string
          example: "60f1b2b3c9e9a12345678901"
        username:
          type: string
          example: "admin_user"
        name:
          type: string
          example: "Admin User"
        type:
          type: string
          enum: ["admin"]
          example: "admin"
      required:
        - _id
        - username
        - name
        - type
    RepCreator:
      type: object
      properties:
        _id:
          type: string
          example: "60f1b2b3c9e9a12345678902"
        username:
          type: string
          example: "rep_user"
        name:
          type: string
          example: "Rep User"
        type:
          type: string
          enum: ["rep"]
          example: "rep"
      required:
        - _id
        - username
        - name
        - type
    ClientCreator:
      type: object
      properties:
        _id:
          type: string
          example: "60f1b2b3c9e9a12345678903"
        username:
          type: string
          example: "client_user"
        name:
          type: string
          example: "Client User"
        type:
          type: string
          enum: ["client"]
          example: "client"
      required:
        - _id
        - username
        - name
        - type
    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: "Client contact 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"
