import { d as defineEventHandler, r as requireAuth, a as getSchemaManager } from '../../../nitro/nitro.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

const openapi_json_get = defineEventHandler(async (event) => {
  var _a;
  await requireAuth(event);
  const schemaManager = getSchemaManager();
  const schemas = schemaManager.getAllSchemas();
  const openapi = {
    openapi: "3.0.0",
    info: {
      title: "Notty API",
      version: "1.0.0",
      description: "Advanced Content Management System API with dynamic schema support, RBAC, and advanced querying capabilities.",
      contact: {
        name: "Notty Support",
        email: "support@notty.local"
      }
    },
    servers: [
      {
        url: "http://localhost:2102",
        description: "Development server"
      }
    ],
    tags: [
      { name: "Admin Auth", description: "Admin authentication and user management" },
      { name: "Content", description: "Dynamic content CRUD operations" },
      { name: "Bulk Operations", description: "Batch update and delete operations" },
      { name: "Publishing", description: "Content publication management" },
      { name: "Aggregation", description: "Data aggregation and analytics" },
      { name: "File Upload", description: "File and media management" },
      { name: "Schema", description: "Schema management and introspection" }
    ],
    components: {
      securitySchemes: {
        bearerAuth: {
          type: "http",
          scheme: "bearer",
          bearerFormat: "JWT",
          description: "Admin JWT token obtained from login endpoint"
        }
      },
      schemas: {
        Error: {
          type: "object",
          properties: {
            error: { type: "boolean", example: true },
            statusCode: { type: "integer", example: 400 },
            statusMessage: { type: "string", example: "Bad Request" },
            message: { type: "string", example: "Validation error" }
          }
        },
        LoginRequest: {
          type: "object",
          required: ["identifier", "password"],
          properties: {
            identifier: { type: "string", example: "admin", description: "Username or email" },
            password: { type: "string", example: "admin123", format: "password" }
          }
        },
        LoginResponse: {
          type: "object",
          properties: {
            success: { type: "boolean", example: true },
            data: {
              type: "object",
              properties: {
                token: { type: "string", example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." },
                user: {
                  type: "object",
                  properties: {
                    id: { type: "integer", example: 1 },
                    username: { type: "string", example: "admin" },
                    email: { type: "string", example: "admin@notty.local" },
                    role: { type: "string", example: "super-admin" }
                  }
                }
              }
            }
          }
        }
      }
    },
    paths: {
      "/api/admin/auth/login": {
        post: {
          tags: ["Admin Auth"],
          summary: "Admin login",
          description: "Authenticate admin user and receive JWT token",
          requestBody: {
            required: true,
            content: {
              "application/json": {
                schema: { $ref: "#/components/schemas/LoginRequest" }
              }
            }
          },
          responses: {
            "200": {
              description: "Login successful",
              content: {
                "application/json": {
                  schema: { $ref: "#/components/schemas/LoginResponse" }
                }
              }
            },
            "401": {
              description: "Invalid credentials",
              content: {
                "application/json": {
                  schema: { $ref: "#/components/schemas/Error" }
                }
              }
            }
          }
        }
      },
      "/api/admin/auth/me": {
        get: {
          tags: ["Admin Auth"],
          summary: "Get current admin user",
          description: "Retrieve currently authenticated admin user information",
          security: [{ bearerAuth: [] }],
          responses: {
            "200": {
              description: "User information retrieved",
              content: {
                "application/json": {
                  schema: {
                    type: "object",
                    properties: {
                      success: { type: "boolean", example: true },
                      data: {
                        type: "object",
                        properties: {
                          id: { type: "integer", example: 1 },
                          username: { type: "string", example: "admin" },
                          email: { type: "string", example: "admin@notty.local" },
                          role: { type: "string", example: "super-admin" }
                        }
                      }
                    }
                  }
                }
              }
            },
            "401": {
              description: "Not authenticated",
              content: {
                "application/json": {
                  schema: { $ref: "#/components/schemas/Error" }
                }
              }
            }
          }
        }
      }
    }
  };
  for (const schema of schemas) {
    const contentType = schema.info.singularName;
    const contentTypePlural = schema.info.pluralName;
    openapi.paths[`/api/content/${contentType}`] = {
      get: {
        tags: ["Content"],
        summary: `Get all ${contentTypePlural}`,
        description: `Retrieve list of ${contentTypePlural} with filtering, sorting, pagination, and population`,
        security: [{ bearerAuth: [] }],
        parameters: [
          {
            name: "filters[field][$operator]",
            in: "query",
            description: "Filter by field with operator ($eq, $ne, $gt, $gte, $lt, $lte, $in, $contains, $startsWith, $endsWith, $null, $notNull)",
            schema: { type: "string" },
            example: "filters[id][$gte]=2"
          },
          {
            name: "sort",
            in: "query",
            description: 'Sort field (supports relations like "category.name")',
            schema: { type: "string" },
            example: "created_at"
          },
          {
            name: "sortOrder",
            in: "query",
            description: "Sort order",
            schema: { type: "string", enum: ["asc", "desc"] },
            example: "desc"
          },
          {
            name: "page",
            in: "query",
            description: "Page number (1-based)",
            schema: { type: "integer", minimum: 1 },
            example: 1
          },
          {
            name: "pageSize",
            in: "query",
            description: "Items per page",
            schema: { type: "integer", minimum: 1, maximum: 100 },
            example: 25
          },
          {
            name: "populate",
            in: "query",
            description: "Comma-separated list of relations to populate",
            schema: { type: "string" },
            example: "category,author"
          },
          {
            name: "search",
            in: "query",
            description: "Full-text search query",
            schema: { type: "string" }
          },
          {
            name: "searchFields",
            in: "query",
            description: "Comma-separated fields to search in",
            schema: { type: "string" }
          }
        ],
        responses: {
          "200": {
            description: "List retrieved successfully",
            content: {
              "application/json": {
                schema: {
                  type: "object",
                  properties: {
                    success: { type: "boolean", example: true },
                    data: { type: "array", items: { type: "object" } },
                    meta: {
                      type: "object",
                      properties: {
                        pagination: {
                          type: "object",
                          properties: {
                            page: { type: "integer" },
                            pageSize: { type: "integer" },
                            pageCount: { type: "integer" },
                            total: { type: "integer" }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      post: {
        tags: ["Content"],
        summary: `Create ${contentType}`,
        description: `Create new ${contentType} entry`,
        security: [{ bearerAuth: [] }],
        requestBody: {
          required: true,
          content: {
            "application/json": {
              schema: {
                type: "object",
                description: `${contentType} fields based on schema`
              }
            }
          }
        },
        responses: {
          "200": {
            description: "Created successfully",
            content: {
              "application/json": {
                schema: {
                  type: "object",
                  properties: {
                    success: { type: "boolean", example: true },
                    data: { type: "object" }
                  }
                }
              }
            }
          }
        }
      }
    };
    openapi.paths[`/api/content/${contentType}/{id}`] = {
      get: {
        tags: ["Content"],
        summary: `Get ${contentType} by ID`,
        security: [{ bearerAuth: [] }],
        parameters: [
          {
            name: "id",
            in: "path",
            required: true,
            schema: { type: "integer" }
          },
          {
            name: "populate",
            in: "query",
            description: "Comma-separated list of relations to populate",
            schema: { type: "string" }
          }
        ],
        responses: {
          "200": {
            description: "Entry retrieved",
            content: {
              "application/json": {
                schema: {
                  type: "object",
                  properties: {
                    success: { type: "boolean", example: true },
                    data: { type: "object" }
                  }
                }
              }
            }
          },
          "404": {
            description: "Entry not found",
            content: {
              "application/json": {
                schema: { $ref: "#/components/schemas/Error" }
              }
            }
          }
        }
      },
      put: {
        tags: ["Content"],
        summary: `Update ${contentType}`,
        security: [{ bearerAuth: [] }],
        parameters: [
          {
            name: "id",
            in: "path",
            required: true,
            schema: { type: "integer" }
          }
        ],
        requestBody: {
          required: true,
          content: {
            "application/json": {
              schema: { type: "object" }
            }
          }
        },
        responses: {
          "200": {
            description: "Updated successfully"
          }
        }
      },
      delete: {
        tags: ["Content"],
        summary: `Delete ${contentType}`,
        security: [{ bearerAuth: [] }],
        parameters: [
          {
            name: "id",
            in: "path",
            required: true,
            schema: { type: "integer" }
          }
        ],
        responses: {
          "200": {
            description: "Deleted successfully"
          }
        }
      }
    };
    openapi.paths[`/api/content/${contentType}/aggregate`] = {
      get: {
        tags: ["Aggregation"],
        summary: `Aggregate ${contentTypePlural}`,
        description: "Perform aggregation queries with GROUP BY and HAVING support",
        security: [{ bearerAuth: [] }],
        parameters: [
          {
            name: "aggregate[alias]",
            in: "query",
            description: "Aggregate function (e.g., aggregate[count]=*, aggregate[avg]=avg:price)",
            required: true,
            schema: { type: "string" },
            example: "aggregate[count]=*"
          },
          {
            name: "groupBy[]",
            in: "query",
            description: "Fields to group by",
            schema: { type: "string" },
            example: "groupBy[]=category_id"
          },
          {
            name: "filters[field][$operator]",
            in: "query",
            description: "WHERE filters",
            schema: { type: "string" }
          },
          {
            name: "having[alias][$operator]",
            in: "query",
            description: "HAVING filters for aggregated results",
            schema: { type: "string" },
            example: "having[count][$gt]=5"
          }
        ],
        responses: {
          "200": {
            description: "Aggregation results",
            content: {
              "application/json": {
                schema: {
                  type: "object",
                  properties: {
                    success: { type: "boolean", example: true },
                    data: {
                      type: "array",
                      items: { type: "object" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    };
    if ((_a = schema.options) == null ? void 0 : _a.draftAndPublish) {
      openapi.paths[`/api/content/${contentType}/{id}/publish`] = {
        put: {
          tags: ["Publishing"],
          summary: `Publish ${contentType}`,
          description: "Publish content immediately or schedule for future",
          security: [{ bearerAuth: [] }],
          parameters: [
            {
              name: "id",
              in: "path",
              required: true,
              schema: { type: "integer" }
            }
          ],
          requestBody: {
            content: {
              "application/json": {
                schema: {
                  type: "object",
                  properties: {
                    publishedAt: {
                      type: "string",
                      format: "date-time",
                      description: "Schedule for future publication (ISO 8601 format)"
                    }
                  }
                }
              }
            }
          },
          responses: {
            "200": {
              description: "Published successfully"
            }
          }
        }
      };
      openapi.paths[`/api/content/${contentType}/{id}/unpublish`] = {
        put: {
          tags: ["Publishing"],
          summary: `Unpublish ${contentType}`,
          description: "Revert content to draft status",
          security: [{ bearerAuth: [] }],
          parameters: [
            {
              name: "id",
              in: "path",
              required: true,
              schema: { type: "integer" }
            }
          ],
          responses: {
            "200": {
              description: "Unpublished successfully"
            }
          }
        }
      };
    }
  }
  openapi.paths["/api/upload"] = {
    post: {
      tags: ["File Upload"],
      summary: "Upload file",
      description: "Upload file or image with automatic processing",
      security: [{ bearerAuth: [] }],
      requestBody: {
        required: true,
        content: {
          "multipart/form-data": {
            schema: {
              type: "object",
              properties: {
                file: {
                  type: "string",
                  format: "binary"
                }
              }
            }
          }
        }
      },
      responses: {
        "200": {
          description: "File uploaded successfully",
          content: {
            "application/json": {
              schema: {
                type: "object",
                properties: {
                  success: { type: "boolean", example: true },
                  data: {
                    type: "object",
                    properties: {
                      id: { type: "integer" },
                      filename: { type: "string" },
                      url: { type: "string" },
                      mime: { type: "string" },
                      size: { type: "integer" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  };
  return openapi;
});

export { openapi_json_get as default };
//# sourceMappingURL=openapi.json.get.mjs.map
