openapi: 3.0.1
info:
  title: Parties REST APIs
  description: Parties Internal REST APIs
  version: '1'
servers:
  - url: 'https://api.plumery.com'
    description: Live Server
paths:
  '/internal/v1/parties/{partyId}':
    get:
      tags:
        - Parties Internal
      operationId: Get Party
      description: Get Party
      parameters:
        - name: partyId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartyResponse'
        '400':
          description: Invalid request was provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestResponse'
        '404':
          description: Party not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundResponse'
        '500':
          description: Internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
      x-internal: true
  '/internal/v1/parties':
    get:
      tags:
        - Parties Internal
      operationId: Get Party details
      description: Get Party details
      parameters:
        - name: userId
          description: |
            The user id for which associated parties are retrieved.
          in: query
          schema:
            pattern: \S
            type: string
        - name: selfIndividual
          description: |
            When value is true, only the selfIndividualParty will be filtered and retrieved. Otherwise all user parties
            are retrieved.
          in: query
          schema:
            type: boolean
        - name: username
          description: |
            The username for which associated parties are retrieved. The search can either be made by username or by userId.
          in: query
          schema:
            type: string
        - name: originParty.qualifiedId
          description: |
            Optional qualified origin party id to filter parties linked to a specific origin party.
            Example: flexcube:LTT:123111121
          in: query
          required: false
          schema:
            type: string
            format: uri
        - $ref: '#/components/parameters/offset'
        - $ref: '#/components/parameters/limit'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PartiesResponse'
        '400':
          description: Invalid request was provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestResponse'
        '404':
          description: Party not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundResponse'
        '500':
          description: Internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
      x-internal: true
  '/internal/v1/parties/{partyId}:add-origin-party':
    post:
      tags:
        - Parties Internal
      operationId: Add Origin Party
      description: Add origin party to an existing party
      parameters:
        - name: partyId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddOriginPartyRequest'
      responses:
        '204':
          description: Origin party added successfully
        '400':
          description: Invalid request was provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestResponse'
        '404':
          description: Party not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotFoundResponse'
        '409':
          description: Origin party already exists for domain
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConflictResponse'
        '500':
          description: Internal server error occurred.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'
      x-internal: true
components:
  parameters:
    offset:
      name: offset
      in: query
      required: false
      example: 0
      schema:
        type: integer
      description: |
        The position of the first result to be returned (pagination offset).
    limit:
      name: limit
      in: query
      required: false
      example: 10
      schema:
        type: integer
      description: |
        The maximum number of results to return (pagination limit).
  schemas:
    FieldErrorCode:
      enum:
        - 'urn:plmr:authentication:auth-orchestrator-api:NOT_BLANK'
        - 'urn:plmr:authentication:auth-orchestrator-api:NOT_NULL'
        - 'urn:plmr:authentication:auth-orchestrator-api:PATTERN'
      type: string
    FieldError:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/FieldErrorCode'
        message:
          type: string
        field:
          type: string
    ErrorCode:
      enum:
      - 'urn:plmr:authentication:auth-orchestrator-api:INTERNAL_SERVER_ERROR'
      - 'urn:plmr:authentication:auth-orchestrator-api:BAD_REQUEST'
      - 'urn:plmr:authentication:auth-orchestrator-api:RESOURCE_UNKNOWN'
      - 'urn:plmr:authentication:auth-orchestrator-api:UNAUTHORIZED'
      - 'urn:plmr:authentication:auth-orchestrator-api:FORBIDDEN'
      - 'urn:plmr:authentication:auth-orchestrator-api:INVALID_PARAM'
      - 'urn:plmr:authentication:auth-orchestrator-api:WEB_APPLICATION'
      - 'urn:plmr:authentication:auth-orchestrator-api:PARTY_NOT_FOUND'
      - 'urn:plmr:authentication:auth-orchestrator-api:MISSING_QUERY_PARAMS'
      - 'urn:plmr:authentication:auth-orchestrator-api:USER_DOES_NOT_EXIST'
      - 'urn:plmr:authentication:auth-orchestrator-api:DOMAIN_ORIGIN_PARTY_ALREADY_EXISTS'
      type: string
      example: 'urn:plmr:authentication:auth-orchestrator-api:UNAUTHORIZED'
    BadRequestResponse:
      description: Bad request response
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
        requestId:
          type: string
        fieldErrors:
          type: array
          items:
            $ref: '#/components/schemas/FieldError'
    NotFoundResponse:
      description: Not found error response
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
        requestId:
          type: string
    InternalServerErrorResponse:
      description: Internal server error response
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
        requestId:
          type: string
        fieldErrors:
          type: array
          items:
            $ref: '#/components/schemas/FieldError'
    ConflictResponse:
      description: Conflict error response
      type: object
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
        requestId:
          type: string
    AddOriginPartyRequest:
      type: object
      required:
        - qualifiedId
        - domain
      properties:
        qualifiedId:
          type: string
          format: uri
          example: 'provider:1234'
        domain:
          $ref: '#/components/schemas/OriginPartyDomain'
    OriginPartyDomain:
      type: string
      enum:
        - PARTIES
        - ACCOUNTS
    OriginParty:
      required:
        - qualifiedId
        - domain
      type: object
      properties:
        qualifiedId:
          type: string
          format: uri
        domain:
          $ref: '#/components/schemas/OriginPartyDomain'
    PartyResponse:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        type:
          type: string
        selfIndividual:
          type: boolean
          description: Indicates if the party is the user's self individual party
        originParties:
          type: array
          items:
            $ref: '#/components/schemas/OriginParty'
    PartiesResponse:
      description: |
        Parties matching the provided filters.
      type: object
      properties:
        count:
          type: integer
          description: Total number of parties matching the filter criteria
          example: 2
        items:
          type: array
          description: List of parties matching the filter criteria
          items:
            $ref: '#/components/schemas/PartyResponse'