openapi: 3.0.3
info:
  title: GOFLOW Enterprise AI OS API
  description: >
    API กลางของ GOFLOW Enterprise AI OS — ครอบคลุม AI Core (NEXUS AI),
    Knowledge, Executive, Booking, Recruitment, Marketplace และ Wallet
  version: 4.0.0
  contact:
    email: dev@goflow.click
  x-goflow-doc: docs/engineering-os/ENG-15
servers:
  - url: https://api.goflow.click/v1
    description: Production
  - url: https://staging-api.goflow.click/v1
    description: Staging
tags:
  - name: Auth
    description: การยืนยันตัวตน
  - name: AI
    description: บริการ AI (NEXUS AI)
  - name: Knowledge
    description: การค้นหาความรู้
  - name: Executive
    description: AI Executive Agents
  - name: Bookings
    description: การจอง Demo
  - name: Recruitment
    description: การสมัครงาน
  - name: Contact
    description: การติดต่อ
  - name: Marketplace
    description: ระบบการค้า
  - name: Wallet
    description: ระบบการเงิน
security:
  - bearerAuth: []
paths:
  /auth/register:
    post:
      tags: [Auth]
      summary: ลงทะเบียนผู้ใช้ใหม่
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RegisterRequest'
      responses:
        '201':
          description: ลงทะเบียนสำเร็จ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
        '409':
          description: อีเมลซ้ำ
  /auth/login:
    post:
      tags: [Auth]
      summary: เข้าสู่ระบบ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
      responses:
        '200':
          description: สำเร็จ — คืน access/refresh token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
  /auth/refresh:
    post:
      tags: [Auth]
      summary: ขอ access token ใหม่
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [refreshToken]
              properties:
                refreshToken:
                  type: string
      responses:
        '200':
          description: สำเร็จ
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthResponse'
  /ai/chat:
    post:
      tags: [AI]
      summary: สนทนากับ NEXUS AI (Production)
      description: >
        reasoning mode: rag-memory-intelligence-fusion-reasoning-v7.3
        (NEXUS AI v7.3 — RAG + Memory Intelligence Fusion)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
      responses:
        '200':
          description: คำตอบจาก AI
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
        '429':
          description: เกิน quota
  /ai/resolve:
    post:
      tags: [AI]
      summary: AI แก้ปัญหา/ทำงานให้สำเร็จ (Agent)
      description: ส่งภารกิจให้ AI Workforce ดำเนินการ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResolveRequest'
      responses:
        '200':
          description: ผลลัพธ์ภารกิจ
          content:
            application/json:
              schema:
                type: object
                properties:
                  taskId:
                    type: string
                  status:
                    type: string
                    enum: [pending, running, done, failed]
                  result:
                    type: object
  /knowledge/search:
    post:
      tags: [Knowledge]
      summary: ค้นหาความรู้ใน Knowledge Base (RAG)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [query]
              properties:
                query:
                  type: string
                os:
                  type: string
                  enum: [ENT, AI, BIZ, ENG, COM, KB]
                limit:
                  type: integer
                  default: 10
      responses:
        '200':
          description: ผลการค้นหา
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/KnowledgeDoc'
  /executive/report:
    get:
      tags: [Executive]
      summary: รายงานจาก AI Executive (CEO/CTO/CFO/COO AI)
      security:
        - bearerAuth: []
      parameters:
        - name: role
          in: query
          schema:
            type: string
            enum: [ceo, cto, cfo, coo]
          description: บทบาทผู้บริหาร AI
      responses:
        '200':
          description: รายงานสรุป
          content:
            application/json:
              schema:
                type: object
                properties:
                  role:
                    type: string
                  summary:
                    type: string
                  metrics:
                    type: object
                  recommendations:
                    type: array
                    items:
                      type: string
  /executive/tasks:
    get:
      tags: [Executive]
      summary: รายการภารกิจของ AI Executive
      security:
        - bearerAuth: []
      responses:
        '200':
          description: รายการภารกิจ
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Task'
  /bookings:
    post:
      tags: [Bookings]
      summary: จองการสาธิต (Demo)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BookingRequest'
      responses:
        '201':
          description: จองสำเร็จ
  /applications:
    post:
      tags: [Recruitment]
      summary: สมัครงาน
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [positionId, name, email]
              properties:
                positionId:
                  type: string
                name:
                  type: string
                email:
                  type: string
                  format: email
                resume:
                  type: string
                  format: binary
      responses:
        '201':
          description: สมัครสำเร็จ
  /contact:
    post:
      tags: [Contact]
      summary: ส่งข้อความติดต่อ
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [name, email, message]
              properties:
                name:
                  type: string
                email:
                  type: string
                  format: email
                topic:
                  type: string
                message:
                  type: string
      responses:
        '201':
          description: ส่งสำเร็จ
  /partners/apply:
    post:
      tags: [Contact]
      summary: สมัครเป็นพาร์ทเนอร์
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [company, email, partnerType]
              properties:
                company:
                  type: string
                email:
                  type: string
                  format: email
                partnerType:
                  type: string
                  enum: [technology, integration, channel]
                description:
                  type: string
      responses:
        '201':
          description: สมัครสำเร็จ
  /marketplace/products:
    get:
      tags: [Marketplace]
      summary: รายการสินค้า
      parameters:
        - name: category
          in: query
          schema:
            type: string
        - name: page
          in: query
          schema:
            type: integer
            default: 1
      responses:
        '200':
          description: รายการสินค้า
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                  total:
                    type: integer
  /wallet/balance:
    get:
      tags: [Wallet]
      summary: ดูยอดเงินใน Wallet
      security:
        - bearerAuth: []
      responses:
        '200':
          description: ยอดเงิน
          content:
            application/json:
              schema:
                type: object
                properties:
                  balance:
                    type: number
                  currency:
                    type: string
                    default: THB
  /wallet/transfer:
    post:
      tags: [Wallet]
      summary: โอนเงิน
      security:
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [toUserId, amount]
              properties:
                toUserId:
                  type: string
                amount:
                  type: number
                  minimum: 1
      responses:
        '200':
          description: โอนสำเร็จ
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  schemas:
    RegisterRequest:
      type: object
      required: [email, password, name]
      properties:
        email:
          type: string
          format: email
        password:
          type: string
          minLength: 8
        name:
          type: string
    LoginRequest:
      type: object
      required: [email, password]
      properties:
        email:
          type: string
          format: email
        password:
          type: string
    AuthResponse:
      type: object
      properties:
        accessToken:
          type: string
        refreshToken:
          type: string
        user:
          type: object
          properties:
            id:
              type: string
            email:
              type: string
            name:
              type: string
    ChatRequest:
      type: object
      required: [message]
      properties:
        message:
          type: string
        agentId:
          type: string
          description: "เลือก AI Agent (default: NEXUS AI)"
        reasoningMode:
          type: string
          default: rag-memory-intelligence-fusion-reasoning-v7.3
        memory:
          type: boolean
          default: true
        knowledge:
          type: boolean
          default: true
    ChatResponse:
      type: object
      properties:
        reply:
          type: string
        sources:
          type: array
          items:
            type: object
            properties:
              docId:
                type: string
              title:
                type: string
              path:
                type: string
        usage:
          type: object
          properties:
            tokens:
              type: integer
            model:
              type: string
    ResolveRequest:
      type: object
      required: [goal]
      properties:
        goal:
          type: string
          description: เป้าหมาย/ภารกิจที่ต้องการให้ AI ทำ
        agentRole:
          type: string
        requireApproval:
          type: boolean
          default: false
    KnowledgeDoc:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        os:
          type: string
        summary:
          type: string
        path:
          type: string
        score:
          type: number
    BookingRequest:
      type: object
      required: [name, email, date, product]
      properties:
        name:
          type: string
        email:
          type: string
          format: email
        company:
          type: string
        product:
          type: string
          enum: [Enterprise OS, AI Workforce, Marketplace, Agri AI, Logistics, Wallet, Investor]
        date:
          type: string
          format: date
        note:
          type: string
    Task:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        status:
          type: string
          enum: [pending, running, review, done, failed]
        agentId:
          type: string
        createdAt:
          type: string
          format: date-time
