openapi: 3.0.0
info:
  title: Customer Api
  version: 1.0.0
servers:
  - url: https://api.cellcast.com

paths:
  /api/v1/user/token/verify:
    post:
      security:
        - BearerAuth: []
      tags:
        - token
      summary: Verify a user token
      responses:
        "200":
          description: Token verification successful
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TokenVerifyResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"
  /api/v1/gateway:
    post:
      security:
        - BearerAuth: []
      tags:
        - sms
      summary: Send a message through the gateway
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SendSMSRequest"
      responses:
        "200":
          description: Message sent successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SendSMSResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"
  /api/v1/gatewaymms:
    post:
      security:
        - BearerAuth: []
      tags:
        - mms
      summary: Send an MMS through the gateway
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/SendMMSRequest"

      responses:
        "200":
          description: Message sent successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SendMMSResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"

  /api/v1/group:
    post:
      security:
        - BearerAuth: []
      tags:
        - contact
      summary: Upload contact subscription
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/UploadContactParam"
      responses:
        "200":
          description: Group created successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UploadContactResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"

  /api/v1/contact/bulk:
    post:
      security:
        - BearerAuth: []
      tags:
        - contact
      summary: Bulk insert contact subscription
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BulkInsertContactParam"
      responses:
        "200":
          description: Contacts created successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BulkInsertContactResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"

  /api/v1/chat:
    post:
      security:
        - BearerAuth: []
      tags:
        - rms
      summary: Send a rms chat message
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateRmsParam"
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CreateRmsResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"

  /api/v1/chat/{number}:
    get:
      security:
        - BearerAuth: []
      tags:
        - rms
      summary: Get chat messages for a specific number
      parameters:
        - name: number
          in: path
          required: true
          description: The phone number to get chat messages for
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/GetRmsListResponse"
        "401":
          description: No token provided
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ResponseError"


components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
  schemas:
    # General Schema
    BaseResponse:
      type: object
      properties:
        app_type:
          type: string
        app_version:
          type: string
        maintainence:
          type: integer
        new_version:
          type: integer
        force_update:
          type: integer
        invalid_token:
          type: integer
        refresh_token:
          type: string
        show_message:
          type: integer
        is_enc:
          type: boolean
        status:
          type: boolean
        message:
          type: string
        message_type:
          type: string
        error:
          $ref: "#/components/schemas/ErrorObject"

    ErrorObject:
      type: object

    ResponseError:
      type: object
      properties:
        code:
          type: integer
        status:
          type: string
        message:
          type: string
        stack:
          type: string

    QueueResponse:
      type: object
      properties:
        Contact:
          type: string
        MessageId:
          type: string
        Result:
          type: string

    QueueResponses:
      type: array
      items:
        $ref: "#/components/schemas/QueueResponse"

    # Enum
    SenderTypeEnum:
      type: string
      enum:
        - customNumber
        - businessName
        - dedicatedNumber
        - "#SharedNum#"

    # Token Verification
    TokenVerifyData:
      type: object
      properties:
        token:
          type: string

    TokenVerifyResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              $ref: "#/components/schemas/TokenVerifyData"

    # Send sms
    SendSMSRequest:
      type: object
      required:
        - message
        - contacts
      properties:
        sender:
          type: string
          description: Sender's phone number
        message:
          type: string
          description: Message to send. To add a new line, use "\r\n" in the message string with only double quotes
        contacts:
          type: array
          items:
            type: string
          description: 'List of recipient phone numbers. For multiple SMS send: ["+61400000000","+61400000001"]'
        senderType:
          type: array
          items:
            $ref: "#/components/schemas/SenderTypeEnum"
          description: Type of sender
        countryCode:
          type: string
          description: Country code

    SendSMSResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: object
              properties:
                queueResponse:
                  $ref: "#/components/schemas/QueueResponses"

    # Send mms
    SendMMSRequest:
      type: object
      required:
        - message
        - contacts
      properties:
        media:
          type: string
          description: Media content (optional)
        senderType:
          type: array
          items:
            $ref: "#/components/schemas/SenderTypeEnum"
          description: Type of sender
        gif:
          type: string
          description: URL of the GIF
        sender:
          type: string
          description: Sender's phone number
        message:
          type: string
          description: Message to send
        contacts:
          type: array
          items:
            type: string
          description: 'List of recipient phone numbers. For multiple SMS send: ["+61400000000","+61400000001"]'
        countryCode:
          type: string
          description: Country code
        optout:
          type: boolean
          description: Opt-out status
        replyStopToOptOut:
          type: boolean
          description: Reply stop to opt-out

    SendMMSResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: object
              properties:
                queueResponse:
                  $ref: "#/components/schemas/QueueResponses"

    # contact
    UploadContactParam:
      type: object
      properties:
        name:
          type: string
          description: Name of uploaded file
        unSubList:
          type: boolean
          description: Whether it is an unsubscribe list
        file:
          type: string
          format: binary
          description: CSV file containing contact data
        mergeLabels:
          type: array
          items:
            $ref: "#/components/schemas/MergeLabel"
          description: List of labels to merge
        tagIds:
          type: array
          items:
            type: string
          description: List of tag IDs

    MergeLabel:
      type: object
      properties:
        oldLabel:
          type: string
        newLabel:
          type: string

    UploadContactResponseData:
      type: object
      properties:
        fields:
          type: array
          items:
            type: string
        groupstatus:
          type: boolean
        tagsId:
          type: array
          items:
            type: string
        addedThrough:
          type: string
        _id:
          type: string
        user:
          type: string
        name:
          type: string
        status:
          type: string
        mergeLabels:
          type: string
        createdBy:
          type: string
        fieldsAndTotalLength:
          type: array
          items:
            type: string
        contacts:
          type: array
          items:
            type: string
        errorLog:
          type: array
          items:
            type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        __v:
          type: integer
        totalContacts:
          type: string
    UploadContactResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: object
              properties:
                group:
                  $ref: "#/components/schemas/UploadContactResponseData"

    BulkInsertContactParam: 
      type: object
      properties:
        contacts: 
          type: array
          items:
            $ref: "#/components/schemas/ContactParam"
    
    ContactParam: 
      type: object
      required:
        - first_name
        - last_name
        - phone_number
      properties:
        first_name: 
          type: string
        last_name: 
          type: string
        phone_number: 
          type: string
    
    BulkInsertContactResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: object
              properties:
                message:
                  type: string

    # rms
    CreateRmsParam:
      type: object
      required:
        - sender
        - number
        - countryCode
      properties:
        sender:
          type: string
          description: Sender's phone number
        number:
          type: array
          items:
            type: string
          description: List of recipient phone numbers
        message:
          type: string
          description: Message to send
        smsTemplateId:
          type: string
          description: SMS template ID
        rmsTemplateId:
          type: string
          description: RMS template ID
        countryCode:
          type: string
          description: Country code

    CreateRmsResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: array
              items:
                type: object
                properties:
                  number:
                    type: string
                  message:
                    type: string

    GetRmsListResponse:
      allOf:
        - $ref: "#/components/schemas/BaseResponse"
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: "#/components/schemas/RmsChatData"

    RmsChatData:
      type: object
      properties:
        _id:
          type: string
        rmsThreadKey:
          type: string
        user:
          type: string
        subscriberNumber:
          type: integer
        templateId:
          type: string
        rmsShortCode:
          type: string
        rmsChat:
          type: array
          items:
            $ref: "#/components/schemas/RmsChatItem"
        createdAt:
          type: string
        updatedAt:
          type: string
        __v:
          type: integer

    RmsChatItem:
      type: object
      properties:
        isDeleted:
          type: boolean
        _id:
          type: string
        rmsContent:
          type: string
        type:
          type: string
        createdAt:
          type: string
