{
  "openapi": "3.0.3",
  "info": {
    "title": "Sama Farm HR AI Gateway",
    "version": "1.0.0",
    "description": "بوابة آمنة لقراءة وتحليل بيانات سما فارم وإنشاء مقترحات تنتظر موافقة الموارد البشرية. لا يوجد اتصال مباشر بقاعدة MySQL."
  },
  "servers": [{"url": "https://samafarm-hr-hhsdfygf.manus.space"}],
  "security": [{"bearerAuth": []}],
  "paths": {
    "/api/ai/health": {
      "get": {
        "security": [],
        "summary": "حالة البوابة والمزودين",
        "responses": {"200": {"description": "Gateway status"}}
      }
    },
    "/api/ai/models": {
      "get": {
        "summary": "النماذج والمزودون المتاحون لحساب الخدمة",
        "responses": {"200": {"description": "Available providers"}, "401": {"description": "Unauthorized"}}
      }
    },
    "/api/ai/query": {
      "post": {
        "summary": "قراءة وتحليل بيانات HR المركزية",
        "description": "تُرسل أقل مجموعة بيانات لازمة للسؤال إلى المزود المختار. لا تُنفذ أي تعديلات.",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/QueryRequest"}}}},
        "responses": {"200": {"description": "AI answer"}, "400": {"description": "Invalid request"}, "403": {"description": "Scope denied"}, "429": {"description": "Rate limit"}}
      }
    },
    "/api/ai/proposals": {
      "post": {
        "summary": "إنشاء مقترح تعديل HR ينتظر موافقة بشرية",
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProposalRequest"}}}},
        "responses": {"202": {"description": "Pending approval"}, "400": {"description": "Invalid proposal"}, "403": {"description": "Scope denied"}}
      }
    }
  },
  "components": {
    "securitySchemes": {"bearerAuth": {"type": "http", "scheme": "bearer", "bearerFormat": "SamaFarmServiceToken"}},
    "schemas": {
      "QueryRequest": {
        "type": "object",
        "required": ["question"],
        "properties": {
          "question": {"type": "string", "maxLength": 4000},
          "provider": {"type": "string", "enum": ["manus", "openai", "anthropic"]},
          "model": {"type": "string", "maxLength": 128}
        }
      },
      "ProposalRequest": {
        "type": "object",
        "required": ["action", "payload"],
        "properties": {
          "action": {"type": "string", "enum": ["add_employee", "delete_employee", "adjust_attendance", "record_absence", "update_salary", "update_employee"]},
          "resourceType": {"type": "string"},
          "resourceId": {"type": "string"},
          "provider": {"type": "string", "enum": ["manus", "openai", "anthropic"]},
          "model": {"type": "string"},
          "payload": {"type": "object"}
        }
      }
    }
  }
}
