openapi: 3.0.0
info:
  version: 1.0.0
  title: ows-abacus-schedule API Specifications
servers:
  - url: 'https://qa-ows-abacus-schedule.theorchard.io'
    description: QA server
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK

  /schedule:
    post:
      summary: Create schedule
      requestBody:
        description: Schedule details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SchedulePostSchema'
      responses:
        200:
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schedule'
  /schedule/{schedule_id}:
    get:
      summary: Get schedule by id.
      parameters:
        - description: schedule unique ID
          name: schedule_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schedule'
    put:
      summary: Updates schedule by id
      parameters:
        - description: schedule unique ID
          name: schedule_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Schedule details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SchedulePutSchema'
      responses:
        200:
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schedule'
  /schedule/{schedule_id}/schedule-attachments/:
    get:
      summary: Get a list of schedule_attachment's by schedule id
      parameters:
      - in: path
        description: Id of the schedule
        name: schedule_id
        required: true
        schema:
          type: integer
      - in: query
        name: limit
        description: The number of items to return (for pagination)
        schema:
          type: integer
          default: 100
      - in: query
        name: offset
        description: The number of items to skip before returning results (for pagination)
        schema:
          type: integer
          default: 0
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduleAttachmentDetail'
        '404':
          description: Schedule does not exist
  /schedules/{target_type}/{target_id}/:
    get:
      summary: Get a list of schedules by target types
      parameters:
      - in: path
        description: type of the target
        name: target_type
        required: true
        schema:
          type: string
      - in: path
        description: Id of the target
        name: target_id
        required: true
        schema:
          type: string
      - in: query
        description: query parameter to return contributor-only schedules
        name: include_only_schedules
        required: false
        schema:
          type: boolean
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Schedule'
  /schedule-attachment/{schedule_attachment_id}/:
    get:
      summary: Get a schedule_attachment
      parameters:
      - in: path
        description: Id of the schedule_attachment
        name: schedule_attachment_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduleAttachmentDetail'
        '404':
          description: ScheduleAttachment does not exist
    delete:
      summary: Soft delete a schedule_attachment
      parameters:
      - in: path
        description: Id of the payment_group_payment_account
        name: schedule_attachment_id
        required: true
        schema:
          type: integer
      responses:
        '204':
          description: success
        '404':
          description: ScheduleAttachment does not exist
  /schedule/{schedule_id}/{target_type}/schedule-attachments/:
    put:
      summary: create/delete schedule attachments
      parameters:
      - in: path
        description: id of the schedule
        name: schedule_id
        required: true
        schema:
          type: integer
      - in: path
        description: target type of schedule attachment
        name: target_type
        required: true
        schema:
          type: string
      requestBody:
        description: a dict of list of target ids that need to be created or deleted
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScheduleAttachmentPutSchema'
      responses:
        '200':
          description: '200 OK'
        '404':
          description: Schedule does not exist
        '400':
          description: Invalid schedule_attachment target type
components:
  schemas:
    Schedule:
      title: Schedule GET
      type: object
      properties:
        schedule_id:
          type: integer
          description: The schedule ID
        schedule_name:
          type: string
          description: Name of the Schedule
        target_id:
          type: string
          description: schedule target ID
        target_type:
          type: string
          description: schedule target type
        conditions:
          type: object
          description: conditions attached to schedule
      example:
        schedule_id: 1
        schedule_name: 'Schedule'
        target_id: '123-123-123'
        target_type: 'contributor'
        conditions: null
        created_at: '2023-02-17'
        created_by: '123-123-123'
        last_modified_at: '2023-02-18'
        last_modified_by: 'abc-abc-abc'
    SchedulePutSchema:
      title: Schedule PUT
      type: object
      properties:
        schedule_name:
          type: string
          description: schedule name
        conditions:
          type: object
          description: schedule conditions
      example:
        schedule_name: 'some schedule'
        conditions: null
    SchedulePostSchema:
      title: Schedule POST
      type: object
      properties:
        schedule_name:
          type: string
          description: schedule name
        conditions:
          type: object
          description: schedule
        target_type:
          type: string
          description: type of target
        target_id:
          type: string
          description: id of target
      example:
        schedule_name: 'some schedule'
        conditions: null
        target_type: 'contributor'
        target_id: '1234-1234-1234-1234'
    ScheduleAttachmentDetail:
      title: ScheduleAttachment detail JSON
      type: object
      properties:
        schedule_attachment_id:
          type: integer
          description: id of the schedule_attachment.
        schedule_id:
          type: integer
          description: id of the schedule.
        target_type:
          type: string
          description: target type of schedule_attachment - contribution.
        target_id:
          type: string
          description: id of specified target type.
      example:
        schedule_attachment_id: 1
        schedule_id: 1
        target_type: contribution
        target_id: '1ccaj378-77b4-4748-9d72-2c4ec90e7753'    
    ScheduleAttachmentPutSchema:
      title: ScheduleAttachment PUT schema   
      type: object
      properties:
        unassigned_target_ids:
          items:
            type: string
          description: a list of target ids to be deleted.
        assigned_target_ids:
          items:
            type: string
          description:  a list of target ids to be created.
      example:
        unassigned_target_ids: ['1bcab370-77b2-4747-9d72-2c4ec90e7753']
        assigned_target_ids: ['1bcab370-77b2-4747-9d72-2c4ec90e7753']

  securitySchemes:
    Orchard-Identity-Id:
      type: apiKey
      in: header
      name: Orchard-Identity-Id
