openapi: 3.0.0
info:
  title: Accounting Run Dashboard
  description: Track and update accounting run step progress
  version: 1.0.0

servers:
  - url: http://localhost:5000/v1
    description: Dev server

paths:
  '/period/{periodId}/steps':
    post:
      tags:
        - period
      summary: Add a new step to a period
      description: ''
      operationId: addStep

      parameters:
        - in: path
          name: periodId
          required: true
          schema:
            $ref: '#/components/schemas/Period/properties/id'

      requestBody:
        description: todo
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Step'

      responses:
        '200':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Period'
        '405':
          description: Invalid input

    get:
      tags:
        - period
      summary: Get an array of steps by period id
      description: Returns a list of steps for the current period
      operationId: getStepsByPeriodId

      parameters:
        - in: path
          required: true
          name: periodId
          schema:
            $ref: '#/components/schemas/Period/properties/id'

      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Step'
        '404':
          description: Not found

  '/period/{periodId}/step/{stepId}':
    put:
      tags:
        - period
      summary: Update an existing step in the active period.
      description: ''
      operationId: updateStep

      requestBody:
        description: todo
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Step'

      parameters:
        - in: path
          name: periodId
          description: Id of the accounting period.
          required: true
          schema:
            $ref: '#/components/schemas/Period/properties/id'
        - in: path
          name: stepId
          description: Id of the steop
          required: true
          schema:
            $ref: '#/components/schemas/Step/properties/api_id'

      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Step'
        '400':
          description: Invalid Request
        '404':
          description: Not found


components:
  schemas:
    Period:
      type: object
      properties:
        id:
          type: integer
          format: int64
          example: 1
        is_quarter_end:
          default: false
          type: boolean
          example: false
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time

    Step:
      type: object
      properties:
        id:
          type: integer
          description: The monthly period id, incremented from Jan 1999
          format: int64
          example: 1
          readOnly: true
        api_id:
          type: string
          readOnly: true
        title:
          type: string
        period_id:
          $ref: '#/components/schemas/Period/properties/id'
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
        skipped:
          type: boolean
        interval:
          type: string
          enum: [monthly, quarterly]
        previous_steps:
          type: array
          items:
            $ref: '#/components/schemas/Step/properties/id'
