openapi: 3.0.3
info:
  title: Repzo API - Day
  version: 1.0.0
  description: OpenAPI specification for Repzo Day endpoints.
servers:
  - url: https://sv.api.repzo.me
paths:
  /day:
    get:
      summary: Find days
      operationId: findDays
      parameters:
        - in: query
          name: params
          schema:
            type: object
            properties:
              _id:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              search:
                type: string
              rep:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              reps:
                oneOf:
                  - type: array
                    items:
                      type: string
                  - type: string
              date:
                type: string
                format: date
              status:
                type: string
                enum: [open, closed, submitted]
              not_working_day:
                type: boolean
              from_date:
                type: string
                format: date
              to_date:
                type: string
                format: date
              from_updatedAt:
                type: number
              from__id:
                type: string
              to__id:
                type: string
              sortBy:
                type: array
                items:
                  type: object
                  properties:
                    field:
                      type: string
                      enum: [_id, createdAt, updatedAt, date]
                    type:
                      type: string
                      enum: [asc, desc]
          description: Query parameters for filtering days
      responses:
        "200":
          description: A list of days
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DayFindResult"
    post:
      summary: Create a day
      operationId: createDay
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/DayCreateBody"
      responses:
        "201":
          description: Day created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DayCreateResult"
  /day/{id}:
    get:
      summary: Get a day by ID
      operationId: getDay
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "200":
          description: Day details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DayGetResult"
components:
  schemas:
    DayFindResult:
      type: object
      description: Result of finding days
      properties:
        data:
          type: array
          items:
            $ref: "#/components/schemas/DaySchema"
        total_result:
          type: number
          description: Total number of days
        current_count:
          type: number
          description: Count of days 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 days per page
    DaySchema:
      type: object
      description: Day schema
      properties:
        _id:
          type: string
          description: Unique identifier for the day
        rep:
          type: string
          description: Representative ID
        date:
          type: string
          format: date
          description: Date of the working day
        startTime:
          type: string
          format: time
          description: Start time of the day
        endTime:
          type: string
          format: time
          description: End time of the day
        status:
          type: string
          enum: [open, closed, submitted]
          description: Status of the day
        not_working_day:
          type: boolean
          description: Server-set flag for days that fall on a scheduled day off of the rep's assigned shift.
        visits:
          type: array
          items:
            type: string
          description: List of visit IDs for the day
        orders:
          type: array
          items:
            type: string
          description: List of order IDs for the day
        activities:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                description: Activity type
              description:
                type: string
                description: Activity description
              timestamp:
                type: string
                format: date-time
                description: Activity timestamp
          description: List of activities for the day
        summary:
          type: object
          properties:
            totalVisits:
              type: number
              description: Total number of visits
            totalOrders:
              type: number
              description: Total number of orders
            totalSales:
              type: number
              description: Total sales amount
          description: Day summary statistics
        notes:
          type: string
          description: Additional notes for the day
        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
    DayCreateBody:
      type: object
      description: Body for creating a day
      required:
        - rep
        - date
      properties:
        rep:
          type: string
          description: Representative ID
        date:
          type: string
          format: date
          description: Date of the working day
        startTime:
          type: string
          format: time
          description: Start time of the day
        notes:
          type: string
          description: Additional notes for the day
        integration_meta:
          type: object
          additionalProperties: true
          description: Integration metadata
    DayCreateResult:
      $ref: "#/components/schemas/DaySchema"
      description: Result of creating a day
    DayGetResult:
      $ref: "#/components/schemas/DaySchema"
      description: Result of getting a day
