{
  "openapi": "3.1.1",
  "info": {
    "title": "email.link.mn API",
    "description": "Amazon SES дээр суурилсан имэйл илгээх үйлчилгээ. link.mn API key-ээр (Authorization: Bearer lk_live_…) хандана. Орчны хувьсагч: LINK_API_KEY, LINK_EMAIL_BASE_URL (анхдагч https://email.link.mn/api/v1). Алдаа нь RFC 9457 Problem Details (type, title, status, detail, code). Үнэ: https://link.mn/services/email",
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://email.link.mn",
      "description": "Production"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "Үйлчилгээ"
        ],
        "summary": "Үйлчилгээний төлөв",
        "description": "Нэвтрэлт шаардахгүй. Хэвийн бол 200 {\"status\":\"ok\"}, өгөгдлийн сан ажиллахгүй бол 503.",
        "operationId": "Health",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/me": {
      "get": {
        "tags": [
          "Имэйл"
        ],
        "summary": "API key-ийн мэдээлэл",
        "description": "Key-ийн link.mn төсөл, орчин (live/test), холбогдсон email.link.mn project-ийг буцаана.",
        "operationId": "GetMe",
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "402": {
            "description": "Payment Required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MeResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [ ]
          }
        ]
      }
    },
    "/api/v1/emails": {
      "post": {
        "tags": [
          "Имэйл"
        ],
        "summary": "Имэйл илгээх",
        "description": "Project-д баталгаажсан домайнаас имэйл илгээнэ. Хүлээн авагч бүр (to+cc+bcc) нэг имэйлээр тооцогдоно. lk_test_ key нь бүх шалгалтыг хийгээд бодитоор илгээхгүй, төлбөр авахгүй. Idempotency-Key header-тэй давтан хүсэлт эхний хариуг буцаана.",
        "operationId": "SendEmail",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ApiSendEmailRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "402": {
            "description": "Payment Required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "202": {
            "description": "Accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiEmailResult"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiEmailResult"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "502": {
            "description": "Bad Gateway",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [ ]
          }
        ]
      }
    },
    "/api/v1/emails/{id}": {
      "get": {
        "tags": [
          "Имэйл"
        ],
        "summary": "Имэйлийн төлөв",
        "description": "queued, sent, delivered, bounced, complained, rejected, delayed, failed.",
        "operationId": "GetEmail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "402": {
            "description": "Payment Required",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "429": {
            "description": "Too Many Requests",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "503": {
            "description": "Service Unavailable",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiEmailResult"
                }
              }
            }
          },
          "404": {
            "description": "Not Found",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        },
        "security": [
          {
            "bearer": [ ]
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "ApiEmailResult": {
        "required": [
          "id",
          "status",
          "project_id"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "from": {
            "type": [
              "null",
              "string"
            ]
          },
          "recipients": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "test": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "project_id": {
            "type": "string"
          }
        }
      },
      "ApiSendEmailRequest": {
        "type": "object",
        "properties": {
          "from": {
            "type": [
              "null",
              "string"
            ]
          },
          "to": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "type": "string"
            }
          },
          "cc": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "type": "string"
            }
          },
          "bcc": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "type": "string"
            }
          },
          "reply_to": {
            "type": [
              "null",
              "array"
            ],
            "items": {
              "type": "string"
            }
          },
          "subject": {
            "type": [
              "null",
              "string"
            ]
          },
          "text": {
            "type": [
              "null",
              "string"
            ]
          },
          "html": {
            "type": [
              "null",
              "string"
            ]
          },
          "tags": {
            "type": [
              "null",
              "object"
            ],
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "HealthResponse": {
        "required": [
          "status"
        ],
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          }
        }
      },
      "LinkedProject": {
        "required": [
          "id",
          "name",
          "sendingAllowed"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "sendingAllowed": {
            "type": "boolean"
          }
        }
      },
      "MeResponse": {
        "required": [
          "projectId",
          "keyId",
          "environment",
          "plan",
          "emailProject"
        ],
        "type": "object",
        "properties": {
          "projectId": {
            "type": "string"
          },
          "keyId": {
            "type": "string"
          },
          "environment": {
            "type": "string"
          },
          "plan": {
            "type": [
              "null",
              "string"
            ]
          },
          "emailProject": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/components/schemas/LinkedProject"
              }
            ]
          }
        }
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": [
              "null",
              "string"
            ]
          },
          "title": {
            "type": [
              "null",
              "string"
            ]
          },
          "status": {
            "pattern": "^-?(?:0|[1-9]\\d*)$",
            "type": [
              "null",
              "integer",
              "string"
            ],
            "format": "int32"
          },
          "detail": {
            "type": [
              "null",
              "string"
            ]
          },
          "instance": {
            "type": [
              "null",
              "string"
            ]
          }
        }
      }
    },
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "description": "link.mn консолоос авсан API key. lk_test_ key нь sandbox (бодитоор илгээхгүй, төлбөргүй).",
        "scheme": "bearer",
        "bearerFormat": "lk_live_… / lk_test_…"
      }
    }
  },
  "tags": [
    {
      "name": "Үйлчилгээ"
    },
    {
      "name": "Имэйл"
    }
  ]
}