openapi: 3.0.3
info:
  title: Repzo API - Route
  version: 1.0.0
  description: OpenAPI specification for Repzo Route endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /route:
    get:
      summary: Find routes
      operationId: findRoutes
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              _id:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              search:
                type: string
              name:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              disabled:
                type: boolean
              from_updatedAt:
                type: number
              from__id:
                type: string
              to__id:
                type: string
              rep_id:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              sortBy:
                type: array
                items:
                  type: object
                  properties:
                    field:
                      type: string
                      enum: [_id, name, day]
                    type:
                      type: string
                      enum: [asc, desc]
          description: Query parameters for filtering routes
      responses:
        "200":
          description: A list of routes
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RouteFindResult"
    post:
      summary: Create a route
      operationId: createRoute
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RouteCreateBody"
      responses:
        "201":
          description: Route created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RouteCreateResult"
  /route/{id}:
    get:
      summary: Get a route by ID
      operationId: getRoute
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Route details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RouteGetResult"
    put:
      summary: Update a route
      operationId: updateRoute
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RouteUpdateBody"
      responses:
        "200":
          description: Route updated
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RouteUpdateResult"
    delete:
      summary: Remove a route
      operationId: removeRoute
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Route removed
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RouteRemoveResult"
components:
  schemas:
    RouteFindResult:
      type: object
      description: Result of finding routes
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/RouteSchema"
        total_result:
          type: number
          description: Total number of routes
        current_count:
          type: number
          description: Count of routes in current page
        total_pages:
          type: number
          description: Total number of pages
        current_page:
          type: number
          description: Current page number
        per_page:
          type: number
          description: Number of routes per page
        first_page_url:
          type: string
          description: URL for the first page
        last_page_url:
          type: string
          description: URL for the last page
        next_page_url:
          type: string
          nullable: true
          description: URL for the next page
        prev_page_url:
          type: string
          nullable: true
          description: URL for the previous page
        path:
          type: string
          description: Base URL path
    RouteSchema:
      type: object
      description: Route schema
      properties:
        _id:
          type: string
          description: Unique identifier for the route
        name:
          type: string
          description: Name of the route
        rep_id:
          type: string
          description: ID of the assigned rep
        day:
          type: string
          enum: [sat, sun, mon, tue, wed, thu, fri]
          description: Day of the week for the route
        clients:
          type: array
          description: List of clients on this route
          items:
            type: object
            properties:
              client_id:
                type: string
                description: Client ID
              priority:
                type: number
                description: Priority order of the client
        disabled:
          type: boolean
          description: Whether the route is disabled
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
        __v:
          type: number
          description: Version number
    RouteCreateBody:
      type: object
      description: Body for creating a route
      required:
        - name
        - rep_id
        - day
        - company_namespace
      properties:
        name:
          type: string
          description: Name of the route
        rep_id:
          type: string
          description: ID of the assigned rep
        day:
          type: string
          enum: [sat, sun, mon, tue, wed, thu, fri]
          description: Day of the week for the route
        clients:
          type: array
          description: List of clients on this route
          items:
            type: object
            properties:
              client_id:
                type: string
                description: Client ID
              priority:
                type: number
                description: Priority order of the client
        disabled:
          type: boolean
          description: Whether the route is disabled
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
    RouteCreateResult:
      $ref: "#/components/schemas/RouteSchema"
      description: Result of creating a route
    RouteGetResult:
      $ref: "#/components/schemas/RouteSchema"
      description: Result of getting a route
    RouteUpdateBody:
      type: object
      description: Body for updating a route
      properties:
        name:
          type: string
          description: Name of the route
        rep_id:
          type: string
          description: ID of the assigned rep
        day:
          type: string
          enum: [sat, sun, mon, tue, wed, thu, fri]
          description: Day of the week for the route
        clients:
          type: array
          description: List of clients on this route
          items:
            type: object
            properties:
              client_id:
                type: string
                description: Client ID
              priority:
                type: number
                description: Priority order of the client
        disabled:
          type: boolean
          description: Whether the route is disabled
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
        company_namespace:
          type: array
          items:
            type: string
          description: Company namespaces
        _id:
          type: string
          description: Unique identifier for the route
        createdAt:
          type: string
          format: date-time
          description: Creation timestamp
        updatedAt:
          type: string
          format: date-time
          description: Last update timestamp
        __v:
          type: number
          description: Version number
    RouteUpdateResult:
      $ref: "#/components/schemas/RouteSchema"
      description: Result of updating a route
    RouteRemoveResult:
      $ref: "#/components/schemas/RouteSchema"
      description: Result of removing a route
