{
  "openapi": "3.1.0",
  "info": {
    "title": "Lucheng GEO First Paid Pilot Staff API",
    "version": "2026-08-17",
    "description": "Staff-only API contract for first paid pilot service confirmations. This is a static implementation contract, not a deployed backend, not payment proof and not AI recommendation proof."
  },
  "servers": [
    {
      "url": "https://lucheng-geo.pages.dev",
      "description": "Static production gray site. Internal API is not deployed in the current phase."
    }
  ],
  "security": [
    {
      "staffBearerAuth": []
    }
  ],
  "paths": {
    "/api/internal/service-confirmations": {
      "get": {
        "summary": "List internal service confirmations",
        "operationId": "listServiceConfirmations",
        "parameters": [
          {
            "name": "readiness_status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/ReadinessStatus"
            }
          },
          {
            "name": "payment_status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/PaymentStatus"
            }
          },
          {
            "name": "customer_brand_name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Staff-only list response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceConfirmationListResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      },
      "post": {
        "summary": "Create a draft service confirmation",
        "operationId": "createServiceConfirmation",
        "description": "Creates a staff-only draft from the 25-field form JSON or a localStorage ledger export. Imported rows must remain draft until human review.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ServiceConfirmationCreateRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Draft created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceConfirmationDetailResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/ValidationError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        }
      }
    },
    "/api/internal/service-confirmations/{id}": {
      "get": {
        "summary": "Read one internal service confirmation",
        "operationId": "getServiceConfirmation",
        "parameters": [
          {
            "$ref": "#/components/parameters/ServiceConfirmationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Service confirmation detail",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ServiceConfirmationDetailResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/internal/service-confirmations/{id}/recompute-readiness": {
      "post": {
        "summary": "Recompute commercial readiness gates",
        "operationId": "recomputeServiceConfirmationReadiness",
        "description": "Recomputes readiness_status, readiness_blockers_json and readiness_warnings_json. This does not approve payment, content publishing or AI outcome claims.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ServiceConfirmationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Readiness recomputed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReadinessResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/internal/service-confirmations/{id}/export": {
      "post": {
        "summary": "Export a signed-off service confirmation snapshot",
        "operationId": "exportServiceConfirmation",
        "description": "Exports a staff archive snapshot. Export is not contract proof, payment proof, invoice proof, official-site publishing proof or AI recommendation proof.",
        "parameters": [
          {
            "$ref": "#/components/parameters/ServiceConfirmationId"
          }
        ],
        "responses": {
          "200": {
            "description": "Archive export",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExportResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "staffBearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Staff-only bearer session. Production implementation must add origin checks, audit logs and least-privilege role checks."
      }
    },
    "parameters": {
      "ServiceConfirmationId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^LC-GEO-SC-[A-Z0-9-]+$"
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing or invalid staff session"
      },
      "Forbidden": {
        "description": "Staff session lacks permission for the requested action"
      },
      "NotFound": {
        "description": "Service confirmation not found"
      },
      "ValidationError": {
        "description": "Input fails service confirmation gate validation"
      }
    },
    "schemas": {
      "ServiceMode": {
        "type": "string",
        "enum": [
          "internal-sample",
          "diagnostic-pilot",
          "monitoring-pilot",
          "customer-paid-draft"
        ]
      },
      "PaymentStatus": {
        "type": "string",
        "enum": [
          "not-started",
          "sample-only",
          "pending",
          "paid",
          "refunded",
          "waived"
        ]
      },
      "InvoiceStatus": {
        "type": "string",
        "enum": [
          "not-started",
          "sample-only",
          "pending",
          "issued",
          "not-required",
          "voided"
        ]
      },
      "ReadinessStatus": {
        "type": "string",
        "enum": [
          "not-ready-for-real-paid-service",
          "ready-for-human-review-not-payment-proof",
          "approved-for-service-start-not-ai-proof"
        ]
      },
      "LegalFinanceReviewStatus": {
        "type": "string",
        "enum": [
          "pending",
          "approved",
          "rejected",
          "not-applicable-sample"
        ]
      },
      "P0EvidenceStatus": {
        "type": "string",
        "enum": [
          "not-submitted",
          "not-accepted",
          "partially-accepted",
          "accepted",
          "not-applicable"
        ]
      },
      "ServiceConfirmationCore": {
        "type": "object",
        "required": [
          "service_confirmation_id",
          "service_mode",
          "service_provider_legal_entity",
          "customer_legal_entity",
          "customer_brand_name",
          "brand_authorization_scope",
          "sponsored_disclosure_accepted",
          "no_ai_outcome_guarantee_accepted",
          "target_question",
          "target_platforms",
          "client_written_confirmation",
          "legal_finance_review_status",
          "p0_evidence_status"
        ],
        "properties": {
          "service_confirmation_id": {
            "type": "string"
          },
          "service_mode": {
            "$ref": "#/components/schemas/ServiceMode"
          },
          "service_provider_legal_entity": {
            "type": "string"
          },
          "customer_legal_entity": {
            "type": "string"
          },
          "customer_brand_name": {
            "type": "string"
          },
          "customer_contact_person_redacted": {
            "type": "string"
          },
          "brand_authorization_scope": {
            "type": "string"
          },
          "public_material_scope": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sponsored_disclosure_accepted": {
            "type": "boolean"
          },
          "no_ai_outcome_guarantee_accepted": {
            "type": "boolean"
          },
          "external_action_authorization": {
            "type": "object",
            "required": [
              "scope",
              "allowedActions"
            ],
            "properties": {
              "scope": {
                "type": "string",
                "enum": [
                  "none",
                  "read-only",
                  "specific-write-actions"
                ]
              },
              "allowedActions": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "selected_tier": {
            "type": "string"
          },
          "quoted_amount_cny": {
            "type": "integer",
            "minimum": 0
          },
          "payment_status": {
            "$ref": "#/components/schemas/PaymentStatus"
          },
          "invoice_status": {
            "$ref": "#/components/schemas/InvoiceStatus"
          },
          "service_start_date": {
            "type": "string",
            "format": "date"
          },
          "service_end_date": {
            "type": "string",
            "format": "date"
          },
          "target_question": {
            "type": "string"
          },
          "target_platforms": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "deliverable_units": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "acceptance_evidence_paths": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "blocked_claims": {
            "type": "string"
          },
          "p0_evidence_status": {
            "$ref": "#/components/schemas/P0EvidenceStatus"
          },
          "client_written_confirmation": {
            "type": "boolean"
          },
          "legal_finance_review_status": {
            "$ref": "#/components/schemas/LegalFinanceReviewStatus"
          }
        }
      },
      "ServiceConfirmationCreateRequest": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ServiceConfirmationCore"
          },
          {
            "type": "object",
            "properties": {
              "source_payload": {
                "type": "object"
              }
            }
          }
        ]
      },
      "ServiceConfirmationRecord": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ServiceConfirmationCore"
          },
          {
            "type": "object",
            "required": [
              "readiness_status",
              "readiness_blockers",
              "readiness_warnings"
            ],
            "properties": {
              "readiness_status": {
                "$ref": "#/components/schemas/ReadinessStatus"
              },
              "readiness_blockers": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "readiness_warnings": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "created_at": {
                "type": "string"
              },
              "updated_at": {
                "type": "string"
              }
            }
          }
        ]
      },
      "ServiceConfirmationListResponse": {
        "type": "object",
        "required": [
          "items",
          "boundary"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ServiceConfirmationRecord"
            }
          },
          "boundary": {
            "type": "string",
            "const": "Staff-only internal list. It is not public customer portal, payment proof, publishing authorization or AI recommendation proof."
          }
        }
      },
      "ServiceConfirmationDetailResponse": {
        "type": "object",
        "required": [
          "record",
          "boundary"
        ],
        "properties": {
          "record": {
            "$ref": "#/components/schemas/ServiceConfirmationRecord"
          },
          "units": {
            "type": "array"
          },
          "authorizations": {
            "type": "array"
          },
          "ai_test_plan": {
            "type": "array"
          },
          "acceptance": {
            "type": "array"
          },
          "audit_logs": {
            "type": "array"
          },
          "boundary": {
            "type": "string"
          }
        }
      },
      "ReadinessResponse": {
        "type": "object",
        "required": [
          "service_confirmation_id",
          "readiness_status",
          "blockers",
          "warnings",
          "boundary"
        ],
        "properties": {
          "service_confirmation_id": {
            "type": "string"
          },
          "readiness_status": {
            "$ref": "#/components/schemas/ReadinessStatus"
          },
          "blockers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "boundary": {
            "type": "string"
          }
        }
      },
      "ExportResponse": {
        "type": "object",
        "required": [
          "exported_at",
          "record",
          "boundary"
        ],
        "properties": {
          "exported_at": {
            "type": "string"
          },
          "record": {
            "$ref": "#/components/schemas/ServiceConfirmationRecord"
          },
          "boundary": {
            "type": "string",
            "const": "Archive export only. Not contract, payment, invoice, publishing or AI outcome proof."
          }
        }
      }
    }
  }
}
