openapi: 3.0.3
info:
  title: Repzo API - Plan
  version: 1.0.0
  description: OpenAPI specification for Repzo Plan endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /plan:
    get:
      summary: Find plans
      operationId: findPlans
      parameters:
        - in: query
          name: params
          schema:
            type: object
          description: Query parameters for filtering plans
      responses:
        "200":
          description: A list of plans
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlanFindResult"
    post:
      summary: Create a plan
      operationId: createPlan
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PlanCreateBody"
      responses:
        "201":
          description: Plan created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlanCreateResult"
  /plan/{id}:
    get:
      summary: Get a plan by ID
      operationId: getPlan
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Plan details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlanGetResult"
    put:
      summary: Update a plan
      operationId: updatePlan
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PlanUpdateBody"
      responses:
        "200":
          description: Plan updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlanUpdateResult"
    delete:
      summary: Disable a plan
      operationId: removePlan
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Plan disabled
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PlanRemoveResult"
components:
  schemas:
    PlanEditor:
      type: object
      properties:
        _id:
          type: string
        type:
          type: string
          enum: [admin, rep]
        rep:
          type: string
        admin:
          type: string
        name:
          type: string
    PlanBuildListItem:
      type: object
      properties:
        calendar:
          type: string
        route:
          type: string
        client:
          type: string
        note:
          type: string
        from:
          type: string
        to:
          type: string
        visit_reason:
          type: string
        visit_note:
          type: string
    PlanBuildEntry:
      type: object
      properties:
        day:
          type: string
          description: "Date in YYYY-MM-DD format"
        list:
          type: array
          items:
            $ref: "#/components/schemas/PlanBuildListItem"
    PlanFindResult:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/Plan"
        meta:
          type: object
    PlanCreateBody:
      type: object
      required:
        - name
        - sync_id
      properties:
        name:
          type: string
        sync_id:
          type: string
        startsAt:
          type: string
          description: "Date in YYYY-MM-DD format"
        endsAt:
          type: string
          description: "Date in YYYY-MM-DD format"
        build:
          type: array
          items:
            $ref: "#/components/schemas/PlanBuildEntry"
        calendars:
          type: array
          items:
            type: string
        disabled:
          type: boolean
        builtAt:
          type: number
    PlanCreateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Plan"
    PlanGetResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Plan"
    PlanUpdateBody:
      type: object
      properties:
        name:
          type: string
        sync_id:
          type: string
        startsAt:
          type: string
        endsAt:
          type: string
        build:
          type: array
          items:
            $ref: "#/components/schemas/PlanBuildEntry"
        calendars:
          type: array
          items:
            type: string
        disabled:
          type: boolean
        builtAt:
          type: number
    PlanUpdateResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Plan"
    PlanRemoveResult:
      type: object
      properties:
        data:
          $ref: "#/components/schemas/Plan"
    Plan:
      type: object
      properties:
        _id:
          type: string
        name:
          type: string
        editor:
          $ref: "#/components/schemas/PlanEditor"
        startsAt:
          type: string
        endsAt:
          type: string
        build:
          type: array
          items:
            $ref: "#/components/schemas/PlanBuildEntry"
        sync_id:
          type: string
        calendars:
          type: array
          items:
            type: string
        disabled:
          type: boolean
        builtAt:
          type: number
        company_namespace:
          type: array
          items:
            type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
