{
  "openapi": "3.1.0",
  "info": {
    "title": "MijPao Public API",
    "description": "ตรวจสอบประวัติความน่าเชื่อถือของเบอร์โทรศัพท์ เลขบัญชีธนาคาร ชื่อบุคคล หรือร้านค้าออนไลน์ จากฐานข้อมูลเบาะแสชุมชน MijPao เปิดให้เรียกได้ฟรี ไม่ต้องใช้ API key (rate limit 5 req/s ต่อ IP)",
    "version": "1.0.0",
    "contact": {
      "name": "MijPao",
      "url": "https://mijpao.com"
    }
  },
  "servers": [
    {
      "url": "https://mijpao.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/public/v1/check": {
      "get": {
        "operationId": "checkMijpaoDatabase",
        "summary": "ตรวจสอบเบาะแสจากฐานข้อมูลชุมชน MijPao",
        "description": "ค้นหาเบอร์โทรศัพท์ เลขบัญชีธนาคาร ชื่อบุคคล หรือร้านค้าออนไลน์ ในฐานข้อมูลเบาะแสชุมชน ผลลัพธ์แบ่งเป็น mitpiracy (น่าเชื่อถือ) และ fraud (ควรระวัง) ระบบจะตรวจจับประเภทการค้นหาอัตโนมัติถ้าไม่ระบุ type ไม่ต้องใช้ API key",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "ค่าที่ต้องการตรวจสอบ เช่น เบอร์โทร (0812345678), เลขบัญชี (1234567890), ชื่อ-นามสกุล (สมชาย ใจดี), หรือชื่อร้านค้า",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 100,
              "examples": ["0812345678", "1234567890", "สมชาย ใจดี"]
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "description": "ประเภทการค้นหา ถ้าไม่ระบุระบบจะตรวจจับอัตโนมัติ (เบอร์โทร 10 หลักขึ้นต้น 0 = phone, ตัวเลข 10-15 หลัก = bank, อื่นๆ = name)",
            "schema": {
              "type": "string",
              "enum": ["bank", "name", "phone", "shop", "other"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "ผลการตรวจสอบสำเร็จ",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CheckResponse" }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "description": "จำนวน request สูงสุดต่อวินาที",
                "schema": { "type": "integer", "example": 5 }
              },
              "X-RateLimit-Remaining": {
                "description": "จำนวน request ที่เหลือในวินาทีปัจจุบัน",
                "schema": { "type": "integer" }
              },
              "X-RateLimit-Reset": {
                "description": "Unix timestamp ที่ rate limit จะ reset",
                "schema": { "type": "integer" }
              }
            }
          },
          "400": {
            "description": "ข้อมูลไม่ถูกต้อง",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "เกินจำนวน request ที่อนุญาต (5 req/s ต่อ IP)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "500": {
            "description": "เกิดข้อผิดพลาดภายในระบบ",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "CheckResponse": {
        "type": "object",
        "required": ["success", "data", "meta"],
        "properties": {
          "success": { "type": "boolean", "example": true },
          "data": {
            "type": "object",
            "required": ["query", "type", "summary", "foundIn", "results"],
            "properties": {
              "query": {
                "type": "string",
                "description": "คำค้นหาที่ใช้",
                "example": "0812345678"
              },
              "type": {
                "type": "string",
                "enum": ["bank", "name", "phone", "shop", "other"],
                "description": "ประเภทการค้นหาที่ใช้"
              },
              "summary": {
                "type": "object",
                "required": ["total", "mitpiracy", "fraud"],
                "properties": {
                  "total": {
                    "type": "integer",
                    "description": "จำนวนผลลัพธ์ทั้งหมด"
                  },
                  "mitpiracy": {
                    "type": "integer",
                    "description": "จำนวนรายงานที่น่าเชื่อถือ (Mitty)"
                  },
                  "fraud": {
                    "type": "integer",
                    "description": "จำนวนรายงานที่ควรระวัง (Mijjy)"
                  }
                }
              },
              "foundIn": {
                "type": "string",
                "nullable": true,
                "enum": ["accounts", "reports", "social_medias", null],
                "description": "แหล่งข้อมูลที่พบผลลัพธ์"
              },
              "results": {
                "type": "object",
                "properties": {
                  "mitpiracy": {
                    "type": "array",
                    "description": "รายการที่น่าเชื่อถือ (มีประวัติดีจากชุมชน)",
                    "items": { "$ref": "#/components/schemas/SearchResult" }
                  },
                  "fraud": {
                    "type": "array",
                    "description": "รายการที่ควรระวัง (มีเบาะแสจากชุมชน)",
                    "items": { "$ref": "#/components/schemas/SearchResult" }
                  }
                }
              }
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "requestId": { "type": "string", "format": "uuid" },
              "timestamp": { "type": "string", "format": "date-time" }
            }
          }
        }
      },
      "SearchResult": {
        "type": "object",
        "required": ["id", "type", "name"],
        "properties": {
          "id": { "type": "string" },
          "type": {
            "type": "string",
            "enum": ["mitty", "mijjy"],
            "description": "mitty = น่าเชื่อถือ, mijjy = ควรระวัง"
          },
          "name": { "type": "string", "description": "ชื่อ (อาจถูก mask บางส่วน)" },
          "createdAt": { "type": "string", "nullable": true, "format": "date-time" },
          "accountNo": { "type": "string", "nullable": true, "description": "เลขบัญชีธนาคาร (mask บางส่วน)" },
          "bankCode": { "type": "string", "nullable": true, "description": "รหัสธนาคาร" },
          "firstname": { "type": "string", "nullable": true },
          "lastname": { "type": "string", "nullable": true },
          "socialMediaName": { "type": "string", "nullable": true },
          "platform": { "type": "string", "nullable": true, "description": "แพลตฟอร์ม เช่น facebook, instagram, line" },
          "profileLink": { "type": "string", "nullable": true, "format": "uri" },
          "detail": { "type": "string", "nullable": true },
          "tags": {
            "type": "array",
            "nullable": true,
            "items": { "type": "string" },
            "description": "แท็กจากชุมชน เช่น หลอกลวง, ส่งของไม่ตรง"
          },
          "source": {
            "type": "string",
            "nullable": true,
            "enum": ["accounts", "reports", "social_medias"]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["success", "error"],
        "properties": {
          "success": { "type": "boolean", "example": false },
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "enum": ["INVALID_REQUEST", "RATE_LIMIT_EXCEEDED", "INTERNAL_ERROR"]
              },
              "message": { "type": "string" }
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "requestId": { "type": "string", "format": "uuid" },
              "timestamp": { "type": "string", "format": "date-time" }
            }
          }
        }
      }
    }
  }
}
