# Generated with protoc-gen-openapi
# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi

openapi: 3.0.3
info:
    title: ""
    version: 0.0.1
paths:
    /v1/admin/tekomis:register:
        post:
            tags:
                - AdminService
            description: |-
                Registers factory devices and their claim codes. Registering a serial
                 again replaces its claim code.
            operationId: AdminService_RegisterTekomis
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.admin.RegisterTekomisRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.admin.RegisterTekomisResponse'
    /v1/admin/users:
        get:
            tags:
                - AdminService
            description: Lists all users.
            operationId: AdminService_ListUsers
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.admin.ListUsersResponse'
    /v1/faqs:
        get:
            tags:
                - FaqService
            description: Lists FAQs, ordered by created_at desc by default. Requires auth (global middleware).
            operationId: FaqService_ListFaqs
            parameters:
                - name: pageSize
                  in: query
                  schema:
                    type: integer
                    format: int32
                - name: pageToken
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.faq.ListFaqsResponse'
    /v1/feedbacks:
        get:
            tags:
                - FeedbackService
            description: List feedback for a user (owner-only). Supports alias "me".
            operationId: FeedbackService_ListMyFeedback
            parameters:
                - name: userId
                  in: query
                  schema:
                    type: string
                - name: pageSize
                  in: query
                  schema:
                    type: integer
                    format: int32
                - name: pageToken
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.feedback.ListMyFeedbackResponse'
        post:
            tags:
                - FeedbackService
            description: Create feedback as the authenticated user. The user_id is inferred from auth; request body user_id is ignored.
            operationId: FeedbackService_CreateFeedback
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.feedback.Feedback'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.feedback.Feedback'
    /v1/feedbacks/{id}:
        get:
            tags:
                - FeedbackService
            description: Get a single feedback (owner-only for now).
            operationId: FeedbackService_GetFeedback
            parameters:
                - name: id
                  in: path
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.feedback.Feedback'
    /v1/support/conversation:answer:
        post:
            tags:
                - SupportService
            description: Answers the latest question and returns the answer and the bot's reply.
            operationId: SupportService_AnswerQuestion
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.support.AnswerQuestionRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.support.AnswerQuestionResponse'
    /v1/support/conversation:start:
        post:
            tags:
                - SupportService
            description: |-
                Starts a new conversation: a greeting followed by the first question.
                 Calling it again starts over.
            operationId: SupportService_StartConversation
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.support.StartConversationRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.support.StartConversationResponse'
    /v1/support/messages:
        get:
            tags:
                - SupportService
            description: Lists the caller's messages, newest first.
            operationId: SupportService_ListMessages
            parameters:
                - name: pageSize
                  in: query
                  schema:
                    type: integer
                    format: int32
                - name: pageToken
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.support.ListMessagesResponse'
    /v1/tekomis:
        get:
            tags:
                - TekomiService
            operationId: TekomiService_ListTekomis
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.ListTekomisResponse'
    /v1/tekomis/{DeviceID}/histories:
        get:
            tags:
                - TekomiService
            operationId: TekomiService_ListHistories
            parameters:
                - name: DeviceID
                  in: path
                  required: true
                  schema:
                    type: string
                - name: since
                  in: query
                  schema:
                    type: string
                - name: limit
                  in: query
                  schema:
                    type: string
                - name: status
                  in: query
                  schema:
                    type: integer
                    format: enum
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.ListHistoriesResponse'
    /v1/tekomis/{deviceId}/histories:computeStats:
        get:
            tags:
                - TekomiService
            description: Returns aggregated statistics for histories of a device.
            operationId: TekomiService_GetHistoryStats
            parameters:
                - name: deviceId
                  in: path
                  description: The device whose histories to aggregate.
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.HistoryStats'
    /v1/tekomis/{id}:
        get:
            tags:
                - TekomiService
            operationId: TekomiService_GetTekomi
            parameters:
                - name: id
                  in: path
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.Tekomi'
    /v1/tekomis/{id}:release:
        post:
            tags:
                - TekomiService
            description: Unpairs the caller's device so it can be claimed again.
            operationId: TekomiService_ReleaseTekomi
            parameters:
                - name: id
                  in: path
                  required: true
                  schema:
                    type: string
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.tekomi.ReleaseTekomiRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.ReleaseTekomiResponse'
    /v1/tekomis:claim:
        post:
            tags:
                - TekomiService
            description: |-
                Pairs the device with the caller. The claim code is printed on the
                 device label; a device already paired with someone else is refused.
            operationId: TekomiService_ClaimTekomi
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.tekomi.ClaimTekomiRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.tekomi.Tekomi'
    /v1/users/{id}:
        get:
            tags:
                - UserService
            operationId: UserService_GetUser
            parameters:
                - name: id
                  in: path
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.user.User'
    /v1/users/{user.id}:
        patch:
            tags:
                - UserService
            operationId: UserService_UpdateUser
            parameters:
                - name: user.id
                  in: path
                  required: true
                  schema:
                    type: string
                - name: updateMask
                  in: query
                  description: The list of fields to update.
                  schema:
                    type: string
                    format: field-mask
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.user.User'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.user.User'
    /v1/users/{userId}/feedbacks:
        get:
            tags:
                - FeedbackService
            description: List feedback for a user (owner-only). Supports alias "me".
            operationId: FeedbackService_ListMyFeedback
            parameters:
                - name: userId
                  in: path
                  required: true
                  schema:
                    type: string
                - name: pageSize
                  in: query
                  schema:
                    type: integer
                    format: int32
                - name: pageToken
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.feedback.ListMyFeedbackResponse'
    /v1/users/{user}/notifications:
        get:
            tags:
                - UserService
            description: Lists notifications for a user.
            operationId: UserService_ListUserNotifications
            parameters:
                - name: user
                  in: path
                  description: The user id.
                  required: true
                  schema:
                    type: string
                - name: pageSize
                  in: query
                  schema:
                    type: integer
                    format: int32
                - name: pageToken
                  in: query
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.user.ListUserNotificationsResponse'
    /v1/users/{user}/notifications:batchUpdateRead:
        post:
            tags:
                - UserService
            description: Batch updates the read status of notifications for a user.
            operationId: UserService_BatchUpdateUserNotifications
            parameters:
                - name: user
                  in: path
                  description: The user id.
                  required: true
                  schema:
                    type: string
            requestBody:
                content:
                    application/json:
                        schema:
                            $ref: '#/components/schemas/api.user.BatchUpdateUserNotificationsRequest'
                required: true
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.user.BatchUpdateUserNotificationsResponse'
    /v1/users/{user}/notifications:unreadCount:
        get:
            tags:
                - UserService
            description: Returns the number of unread notifications for a user (the app badge).
            operationId: UserService_GetUnreadNotificationCount
            parameters:
                - name: user
                  in: path
                  description: The user id.
                  required: true
                  schema:
                    type: string
            responses:
                "200":
                    description: OK
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/api.user.GetUnreadNotificationCountResponse'
components:
    schemas:
        api.admin.ListUsersResponse:
            type: object
            properties:
                users:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.user.User'
        api.admin.RegisterTekomisRequest:
            required:
                - devices
            type: object
            properties:
                devices:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.admin.RegisterTekomisRequest_Device'
                    description: At most 500 devices per call.
        api.admin.RegisterTekomisRequest_Device:
            required:
                - serial
                - claimCode
            type: object
            properties:
                serial:
                    type: string
                claimCode:
                    type: string
                    description: 12 to 64 letters or digits once spaces and dashes are removed.
        api.admin.RegisterTekomisResponse:
            type: object
            properties:
                count:
                    type: integer
                    description: Number of devices registered.
                    format: uint32
        api.faq.Faq:
            type: object
            properties:
                id:
                    type: string
                question:
                    type: string
                answer:
                    type: string
                createdAt:
                    type: string
                    format: date-time
                updatedAt:
                    type: string
                    format: date-time
            description: FAQ resource (minimal first iteration)
        api.faq.ListFaqsResponse:
            type: object
            properties:
                faqs:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.faq.Faq'
                nextPageToken:
                    type: string
        api.feedback.Feedback:
            type: object
            properties:
                id:
                    type: string
                userId:
                    type: string
                category:
                    type: string
                subject:
                    type: string
                message:
                    type: string
                status:
                    type: string
                createdAt:
                    type: string
                    format: date-time
                updatedAt:
                    type: string
                    format: date-time
            description: Feedback resource
        api.feedback.ListMyFeedbackResponse:
            type: object
            properties:
                feedback:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.feedback.Feedback'
                nextPageToken:
                    type: string
        api.support.AnswerQuestionRequest:
            required:
                - questionId
                - optionId
            type: object
            properties:
                questionId:
                    type: string
                    description: ID of the question being answered. Must be the latest bot message.
                optionId:
                    type: string
                    description: One of the question's options.
        api.support.AnswerQuestionResponse:
            type: object
            properties:
                messages:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.support.Message'
                    description: The stored answer followed by the bot's reply.
        api.support.ListMessagesResponse:
            type: object
            properties:
                messages:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.support.Message'
                nextPageToken:
                    type: string
        api.support.Message:
            type: object
            properties:
                id:
                    type: string
                sender:
                    type: integer
                    format: enum
                text:
                    type: string
                options:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.support.Message_Option'
                    description: Options of a bot question. Empty for greetings, answers and the final message.
                layout:
                    type: integer
                    format: enum
                createTime:
                    type: string
                    format: date-time
        api.support.Message_Option:
            type: object
            properties:
                id:
                    type: string
                label:
                    type: string
        api.support.StartConversationRequest:
            type: object
            properties: {}
        api.support.StartConversationResponse:
            type: object
            properties:
                messages:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.support.Message'
                    description: The greeting and the first question, in order.
        api.tekomi.ClaimTekomiRequest:
            required:
                - serial
                - claimCode
            type: object
            properties:
                serial:
                    type: string
                    description: Serial printed on the device.
                claimCode:
                    type: string
                    description: Claim code printed on the device label. Case, spaces and dashes are ignored.
        api.tekomi.Control:
            type: object
            properties:
                power:
                    type: boolean
                paused:
                    type: boolean
                childLock:
                    type: boolean
        api.tekomi.History:
            type: object
            properties:
                timestamp:
                    type: string
                    format: date-time
                status:
                    type: string
                message:
                    type: string
                consumption:
                    type: integer
                    format: uint32
                result:
                    type: number
                    format: double
                workedTime:
                    pattern: ^-?(?:0|[1-9][0-9]{0,11})(?:\.[0-9]{1,9})?s$
                    type: string
                timeHandleError:
                    type: string
                    format: date-time
        api.tekomi.HistoryStats:
            type: object
            properties:
                runCount:
                    type: integer
                    description: Number of successful runs.
                    format: uint32
                producedWeightKg:
                    type: number
                    description: Total fertilizer produced (kg) from successful runs.
                    format: double
                collectedWeightKg:
                    type: number
                    description: Total fertilizer collected (kg). Currently 0 until supported.
                    format: double
                usedAtHomeWeightKg:
                    type: number
                    description: Total fertilizer used at home (kg). Currently 0 until supported.
                    format: double
            description: Aggregated statistics of histories for a device.
        api.tekomi.ListHistoriesResponse:
            type: object
            properties:
                histories:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.tekomi.History'
        api.tekomi.ListTekomisResponse:
            type: object
            properties:
                tekomis:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.tekomi.Tekomi'
        api.tekomi.ReleaseTekomiRequest:
            required:
                - id
            type: object
            properties:
                id:
                    type: string
        api.tekomi.ReleaseTekomiResponse:
            type: object
            properties: {}
        api.tekomi.Tekomi:
            type: object
            properties:
                id:
                    type: string
                sessionId:
                    type: string
                version:
                    type: string
                control:
                    $ref: '#/components/schemas/api.tekomi.Control'
                networkType:
                    type: integer
                    format: enum
                remainingTime:
                    pattern: ^-?(?:0|[1-9][0-9]{0,11})(?:\.[0-9]{1,9})?s$
                    type: string
                serial:
                    type: string
                status:
                    type: string
                workMode:
                    type: string
                signal:
                    type: integer
                    description: Signal strength of the active connection (Wi-Fi or cellular); 0 for ethernet or unknown.
                    format: int32
                wifiSsid:
                    type: string
                    description: SSID when connected over Wi-Fi. The Wi-Fi password is never returned.
                errors:
                    type: array
                    items:
                        type: string
                lastSeen:
                    type: string
                    description: Time of the device's last sys_info report.
                    format: date-time
        api.user.BatchUpdateUserNotificationsRequest:
            required:
                - parent
                - notificationIds
            type: object
            properties:
                parent:
                    type: string
                notificationIds:
                    type: array
                    items:
                        type: string
                read:
                    type: boolean
            description: Request to batch update notification read status. parent must be users/{uid}.
        api.user.BatchUpdateUserNotificationsResponse:
            type: object
            properties:
                updatedCount:
                    type: string
        api.user.GetUnreadNotificationCountResponse:
            type: object
            properties:
                unreadCount:
                    type: string
        api.user.ListUserNotificationsResponse:
            type: object
            properties:
                notifications:
                    type: array
                    items:
                        $ref: '#/components/schemas/api.user.Notification'
                nextPageToken:
                    type: string
        api.user.Notification:
            type: object
            properties:
                id:
                    type: string
                title:
                    type: string
                body:
                    type: string
                createTime:
                    type: string
                    format: date-time
                read:
                    type: boolean
            description: A user notification.
        api.user.User:
            type: object
            properties:
                id:
                    type: string
                phoneNumber:
                    type: string
                email:
                    type: string
                fullName:
                    type: string
                dateOfBirth:
                    type: string
                    format: date-time
                city:
                    type: string
                address:
                    type: string
                photoUrl:
                    type: string
                status:
                    type: integer
                    format: enum
                emailVerified:
                    type: boolean
                phoneNumberVerified:
                    type: boolean
                role:
                    type: integer
                    format: enum
tags:
    - name: AdminService
      description: |-
        AdminService holds the RPCs that only admins may call. Keeping them out of
         the resource services keeps them out of the app's service clients, and lets
         a gateway restrict the whole admin surface by the /v1/admin/ prefix or by
         this service's name. Each RPC still checks that the caller has the ADMIN role.
    - name: FaqService
    - name: FeedbackService
    - name: SupportService
      description: |-
        SupportService is the scripted support chat. The bot asks a question with a
         fixed set of options; the user answers by choosing one, and the bot replies
         with the next question. A question without options ends the conversation.
    - name: TekomiService
    - name: UserService
