openapi: 3.0.3
info:
  title: Repzo API - Calendar
  version: 1.0.0
  description: OpenAPI specification for Repzo Calendar endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /calendar:
    get:
      summary: Find calendars
      operationId: findCalendars
      parameters:
        - in: query
          name: params
          schema:
            type: object
          description: Query parameters for filtering calendars
      responses:
        "200":
          description: A list of calendars
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CalendarFindResult"
    post:
      summary: Create a calendar
      operationId: createCalendar
      parameters:
        - in: query
          name: assignTo
          schema:
            type: string
          description: Plan ID to assign the new calendar to
        - in: query
          name: assignedToMe
          schema:
            type: boolean
          description: When true, assigns the new calendar to the current rep's assigned plan
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CalendarCreateBody"
      responses:
        "201":
          description: Calendar created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CalendarCreateResult"
  /calendar/{id}:
    get:
      summary: Get a calendar by ID
      operationId: getCalendar
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Calendar details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CalendarGetResult"
    put:
      summary: Update a calendar
      operationId: updateCalendar
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CalendarUpdateBody"
      responses:
        "200":
          description: Calendar updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CalendarUpdateResult"
    delete:
      summary: Disable a calendar
      operationId: removeCalendar
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Calendar disabled
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CalendarRemoveResult"
components:
  schemas:
    CalendarType:
      type: string
      enum: [weekly, weeklyGroup]
    CalendarDay:
      type: string
      enum: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
    CalendarUser:
      type: object
      properties:
        _id:
          type: string
        type:
          type: string
          enum: [admin, rep]
        rep:
          type: string
        admin:
          type: string
        name:
          type: string
    CalendarClientEntry:
      type: object
      properties:
        client:
          type: string
        from:
          type: string
        to:
          type: string
        visit_reason:
          type: string
        visit_note:
          type: string
    CalendarWeeklyDetails:
      type: object
      properties:
        type:
          type: string
          enum: [weekly]
        days:
          type: array
          items:
            $ref: "#/components/schemas/CalendarDay"
        every:
          type: number
    CalendarDaysGroup:
      type: object
      properties:
        days:
          type: array
          items:
            $ref: "#/components/schemas/CalendarDay"
    CalendarWeeklyGroupDetails:
      type: object
      properties:
        type:
          type: string
          enum: [weeklyGroup]
        daysGroups:
          type: array
          items:
            $ref: "#/components/schemas/CalendarDaysGroup"
        groupSize:
          type: number
    CalendarDetails:
      oneOf:
        - $ref: "#/components/schemas/CalendarWeeklyDetails"
        - $ref: "#/components/schemas/CalendarWeeklyGroupDetails"
    CalendarFindResult:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Calendar"
        meta:
          type: object
    CalendarCreateBody:
      type: object
      required:
        - name
        - type
        - details
        - sync_id
        - startsAt
      properties:
        name:
          type: string
        type:
          $ref: "#/components/schemas/CalendarType"
        details:
          $ref: "#/components/schemas/CalendarDetails"
        sync_id:
          type: string
        startsAt:
          type: string
          description: "Date in YYYY-MM-DD format"
        endsAt:
          type: string
          description: "Date in YYYY-MM-DD format"
        routes:
          type: array
          items:
            type: string
        clients:
          type: array
          items:
            $ref: "#/components/schemas/CalendarClientEntry"
        occurrences:
          type: number
        disabled:
          type: boolean
        note:
          type: string
        visit_reason:
          type: string
        visit_note:
          type: string
    CalendarCreateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Calendar"
    CalendarGetResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Calendar"
    CalendarUpdateBody:
      type: object
      properties:
        name:
          type: string
        type:
          $ref: "#/components/schemas/CalendarType"
        details:
          $ref: "#/components/schemas/CalendarDetails"
        sync_id:
          type: string
        startsAt:
          type: string
        endsAt:
          type: string
        routes:
          type: array
          items:
            type: string
        clients:
          type: array
          items:
            $ref: "#/components/schemas/CalendarClientEntry"
        occurrences:
          type: number
        disabled:
          type: boolean
        note:
          type: string
        visit_reason:
          type: string
        visit_note:
          type: string
    CalendarUpdateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Calendar"
    CalendarRemoveResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Calendar"
    Calendar:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        type:
          $ref: "#/components/schemas/CalendarType"
        details:
          $ref: "#/components/schemas/CalendarDetails"
        creator:
          $ref: "#/components/schemas/CalendarUser"
        editor:
          $ref: "#/components/schemas/CalendarUser"
        routes:
          type: array
          items:
            type: string
        sync_id:
          type: string
        clients:
          type: array
          items:
            $ref: "#/components/schemas/CalendarClientEntry"
        occurrences:
          type: number
        startsAt:
          type: string
        endsAt:
          type: string
        disabled:
          type: boolean
        note:
          type: string
        visit_reason:
          type: string
        visit_note:
          type: string
        company_namespace:
          type: array
          items:
            type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
