openapi: 3.0.3
info:
  title: Longhorn OEE Analysis Web API
  description: |
    製造業向け OEE（総合設備効率）Web API。ショット分析・セット分析・What-if、
    工場長診断（`diagnosis.engine: foreman`）を返します。
    認証は JSON の `api_key`、または `Authorization: Bearer` / `X-API-KEY`。
    デモキー `956-LONGHORN-DEMO-xyz-abc` は算出のみ（履歴非保存）。
    MCP: https://longhorn.956.jp/mcp
  version: "1.0.0"
  contact:
    name: 956 Inc.
    url: https://www.956.jp/contact
servers:
  - url: https://longhorn.956.jp
security:
  - ApiKeyHeader: []
  - ApiKeyBearer: []
  - ApiKeyBody: []
tags:
  - name: oee
    description: OEE 算出と履歴取得
paths:
  /api/v1/oee/oee_shot:
    post:
      tags: [oee]
      operationId: oeeShot
      summary: ショット分析（ライブOEE）
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ShotRequest"
            example:
              api_key: YOUR_API_KEY
              keyword: 鋳造ライン
              oee_parameters:
                planned_production_time_sec: 36000
                planned_downtime_sec: 1800
                loss_time_sec: 30
                total_count: 1000
                defect_count: 20
                ideal_cycle_time_sec: 30
      responses:
        "200":
          description: 算出成功。`diagnosis` に工場長診断を同梱。
        "401":
          description: APIキー不正
        "422":
          description: 入力エラー
  /api/v1/oee/oee_set:
    post:
      tags: [oee]
      operationId: oeeSet
      summary: セット分析（期間OEE）
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/SetRequest"
      responses:
        "200":
          description: 期間OEEと日次推移
  /api/v1/oee/oee_whatif:
    post:
      tags: [oee]
      operationId: oeeWhatIf
      summary: What-if（改善仮定のOEE試算）
      description: |
        履歴非保存。最大8シナリオ。省略時は zero_defects / zero_stops /
        cut_defects_10pct / cycle_minus_5pct。zero_stops は停止時間をゼロにし回収生産を上乗せ。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/WhatIfRequest"
      responses:
        "200":
          description: baseline と scenarios
  /api/v1/oee/retrieve_shot:
    get:
      tags: [oee]
      operationId: retrieveShot
      summary: ショット履歴取得
      parameters:
        - $ref: "#/components/parameters/ApiKeyQuery"
        - name: keyword
          in: query
          schema: { type: string }
        - name: from_time
          in: query
          schema: { type: string }
        - name: count
          in: query
          schema: { type: integer, default: 50 }
      responses:
        "200":
          description: oee_metrics
  /api/v1/oee/retrieve_set:
    get:
      tags: [oee]
      operationId: retrieveSet
      summary: セット履歴取得
      parameters:
        - $ref: "#/components/parameters/ApiKeyQuery"
        - name: keyword
          in: query
          schema: { type: string }
        - name: from_date
          in: query
          schema: { type: string }
        - name: until_date
          in: query
          schema: { type: string }
      responses:
        "200":
          description: oee_metrics
  /mcp:
    post:
      tags: [oee]
      operationId: mcpRpc
      summary: MCP JSON-RPC（Claude / ChatGPT ツール呼び出し）
      description: |
        methods: initialize, tools/list, tools/call, ping。
        tools: oee_shot, oee_set, oee_whatif, oee_retrieve_shot。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
            example:
              jsonrpc: "2.0"
              id: 1
              method: initialize
              params: { protocolVersion: "2025-03-26" }
      responses:
        "200":
          description: JSON-RPC 応答
    get:
      tags: [oee]
      operationId: mcpDocs
      summary: MCP 接続案内（HTML） / マニフェスト（JSON）
      responses:
        "200":
          description: ドキュメントまたは manifest
components:
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-API-KEY
    ApiKeyBearer:
      type: http
      scheme: bearer
    ApiKeyBody:
      type: apiKey
      in: query
      name: api_key
  parameters:
    ApiKeyQuery:
      name: api_key
      in: query
      schema: { type: string }
  schemas:
    OeeParameters:
      type: object
      required:
        - planned_production_time_sec
        - ideal_cycle_time_sec
        - total_count
        - defect_count
      properties:
        planned_production_time_sec: { type: number }
        planned_downtime_sec: { type: number }
        loss_time_sec: { type: number }
        ideal_cycle_time_sec: { type: number }
        total_count: { type: integer }
        defect_count: { type: integer }
        keyword: { type: string }
    ShotRequest:
      type: object
      required: [oee_parameters]
      properties:
        api_key: { type: string }
        keyword: { type: string }
        oee_parameters:
          $ref: "#/components/schemas/OeeParameters"
    SetRequest:
      type: object
      required: [daily_data]
      properties:
        api_key: { type: string }
        keyword: { type: string }
        daily_data:
          type: array
          items:
            allOf:
              - $ref: "#/components/schemas/OeeParameters"
              - type: object
                required: [date]
                properties:
                  date: { type: string, example: "2026-09-01" }
    WhatIfRequest:
      allOf:
        - $ref: "#/components/schemas/ShotRequest"
        - type: object
          properties:
            scenarios:
              type: array
              items:
                type: object
                properties:
                  preset:
                    type: string
                    enum: [zero_defects, zero_stops, cut_defects_10pct, cycle_minus_5pct]
                  label: { type: string }
                  changes:
                    $ref: "#/components/schemas/OeeParameters"
