{
    "openapi": "3.1.0",
    "info": {
        "title": "Qirim API",
        "version": "1.0.0",
        "description": "WhatsApp gateway untuk OTP, notifikasi, dan chatbot. Semua endpoint butuh header X-Api-Key."
    },
    "servers": [
        {
            "url": "https://qirim.qapuasmedia.tech/api/v1"
        }
    ],
    "security": [
        {
            "ApiKeyAuth": []
        }
    ],
    "components": {
        "securitySchemes": {
            "ApiKeyAuth": {
                "type": "apiKey",
                "in": "header",
                "name": "X-Api-Key"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "success": {
                        "type": "boolean",
                        "example": false
                    },
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string",
                                "example": "otp_incorrect"
                            },
                            "message": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    },
    "paths": {
        "/health": {
            "get": {
                "summary": "Health check",
                "security": [],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/otp/request": {
            "post": {
                "summary": "Minta & kirim OTP via WhatsApp",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "phone"
                                ],
                                "properties": {
                                    "phone": {
                                        "type": "string",
                                        "example": "08123456789"
                                    },
                                    "purpose": {
                                        "type": "string",
                                        "example": "login"
                                    },
                                    "code_length": {
                                        "type": "integer",
                                        "minimum": 4,
                                        "maximum": 8
                                    },
                                    "ttl": {
                                        "type": "integer",
                                        "minimum": 30,
                                        "maximum": 1800
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OTP terkirim",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "success": {
                                            "type": "boolean",
                                            "example": true
                                        },
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "request_id": {
                                                    "type": "string"
                                                },
                                                "phone": {
                                                    "type": "string",
                                                    "example": "628123456789"
                                                },
                                                "expires_in": {
                                                    "type": "integer",
                                                    "example": 300
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "429": {
                        "description": "resend_cooldown / daily_limit",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/otp/verify": {
            "post": {
                "summary": "Verifikasi kode OTP",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "phone",
                                    "code"
                                ],
                                "properties": {
                                    "phone": {
                                        "type": "string",
                                        "example": "08123456789"
                                    },
                                    "code": {
                                        "type": "string",
                                        "example": "123456"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Terverifikasi",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "success": {
                                            "type": "boolean",
                                            "example": true
                                        },
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "verified": {
                                                    "type": "boolean",
                                                    "example": true
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "otp_incorrect / otp_expired",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/otp/resend": {
            "post": {
                "summary": "Kirim ulang OTP (kena cooldown)",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "phone"
                                ],
                                "properties": {
                                    "phone": {
                                        "type": "string"
                                    },
                                    "purpose": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "OK"
                    },
                    "429": {
                        "description": "resend_cooldown"
                    }
                }
            }
        },
        "/notifications/send": {
            "post": {
                "summary": "Kirim notifikasi WhatsApp (text/media/template)",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "to",
                                    "type"
                                ],
                                "properties": {
                                    "to": {
                                        "oneOf": [
                                            {
                                                "type": "string"
                                            },
                                            {
                                                "type": "array",
                                                "items": {
                                                    "type": "string"
                                                }
                                            }
                                        ],
                                        "example": "08123456789"
                                    },
                                    "type": {
                                        "type": "string",
                                        "enum": [
                                            "text",
                                            "media",
                                            "template"
                                        ]
                                    },
                                    "text": {
                                        "type": "string"
                                    },
                                    "media_url": {
                                        "type": "string"
                                    },
                                    "mediatype": {
                                        "type": "string",
                                        "enum": [
                                            "image",
                                            "video",
                                            "document",
                                            "audio"
                                        ]
                                    },
                                    "caption": {
                                        "type": "string"
                                    },
                                    "template": {
                                        "type": "string"
                                    },
                                    "vars": {
                                        "type": "object"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "202": {
                        "description": "Masuk antrian",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "success": {
                                            "type": "boolean",
                                            "example": true
                                        },
                                        "data": {
                                            "type": "object",
                                            "properties": {
                                                "batch_id": {
                                                    "type": "string"
                                                },
                                                "accepted": {
                                                    "type": "integer"
                                                },
                                                "queued": {
                                                    "type": "integer"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/notifications/{batchId}": {
            "get": {
                "summary": "Status pengiriman batch",
                "parameters": [
                    {
                        "name": "batchId",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "404": {
                        "description": "not_found"
                    }
                }
            }
        }
    }
}