// @ts-nocheck
export const systemSchemas = {
    schemas: [
        {
            collectionName: "baasix_SchemaDefinition",
            schema: {
                name: "SchemaDefinition",
                timestamps: true,
                fields: {
                    collectionName: {
                        type: "String",
                        primaryKey: true,
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    schema: { type: "JSON", allowNull: false, SystemGenerated: "true" },
                },
            },
        },
        {
            collectionName: "baasix_Role",
            schema: {
                name: "Role",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    name: { type: "String", allowNull: false, SystemGenerated: "true" },
                    description: { type: "String", SystemGenerated: "true" },
                    isTenantSpecific: {
                        type: "Boolean",
                        allowNull: false,
                        defaultValue: true,
                        SystemGenerated: "true",
                        description: "Indicates if role permissions apply within tenant context",
                    },
                    canInviteRoleIds: {
                        type: "JSON",
                        allowNull: true,
                        defaultValue: [],
                        SystemGenerated: "true",
                        description: "Array of role IDs this role can invite",
                    },
                    permissions: {
                        relType: "HasMany",
                        target: "baasix_Permission",
                        foreignKey: "role_Id",
                        as: "permissions",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                    userRoles: {
                        relType: "HasMany",
                        target: "baasix_UserRole",
                        foreignKey: "role_Id",
                        as: "userRoles",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                },
                indexes: [
                    {
                        fields: ["name"],
                        unique: true,
                        name: "baasix_Role_name_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Permission",
            schema: {
                name: "Permission",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    action: { type: "String", allowNull: false, SystemGenerated: "true" },
                    collection: { type: "String", allowNull: false, SystemGenerated: "true" },
                    role_Id: { type: "UUID", allowNull: false, SystemGenerated: "true" },
                    fields: { type: "JSON", SystemGenerated: "true" },
                    defaultValues: { type: "JSON", SystemGenerated: "true" },
                    conditions: { type: "JSON", SystemGenerated: "true" },
                    relConditions: { type: "JSON", SystemGenerated: "true" },
                    role: {
                        relType: "BelongsTo",
                        target: "baasix_Role",
                        foreignKey: "role_Id",
                        as: "role",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
                indexes: [
                    {
                        fields: ["role_Id", "collection", "action"],
                        unique: true,
                        name: "baasix_Permission_action_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_UserRole",
            schema: {
                name: "UserRole",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    user_Id: { type: "UUID", allowNull: false, SystemGenerated: "true" },
                    role_Id: { type: "UUID", allowNull: false, SystemGenerated: "true" },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "user_Id",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        onDelete: "CASCADE",
                        showAs: ["fullName", " (", "email", ")", " "],
                    },
                    role: {
                        relType: "BelongsTo",
                        target: "baasix_Role",
                        foreignKey: "role_Id",
                        as: "role",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
            },
        },
        {
            collectionName: "baasix_Tenant",
            schema: {
                name: "Tenant",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    name: { type: "String", allowNull: false, SystemGenerated: "true" },
                    userRoles: {
                        relType: "HasMany",
                        target: "baasix_UserRole",
                        foreignKey: "tenant_Id",
                        as: "userRoles",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                },
                indexes: [
                    {
                        fields: ["name"],
                        unique: true,
                        name: "baasix_Tenant_name_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_User",
            schema: {
                name: "User",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    firstName: { type: "String", allowNull: false, SystemGenerated: "true" },
                    lastName: { type: "String", allowNull: true, SystemGenerated: "true" },
                    fullName: {
                        type: "VIRTUAL",
                        calculated: "COALESCE(\"firstName\", '') || ' ' || COALESCE(\"lastName\", '')",
                        SystemGenerated: "true",
                    },
                    phone: { type: "String", allowNull: true, SystemGenerated: "true" },
                    email: { type: "String", allowNull: true, SystemGenerated: "true" },
                    emailVerified: { type: "Boolean", allowNull: false, defaultValue: false, SystemGenerated: "true" },
                    avatar_Id: { type: "UUID", SystemGenerated: "true" },
                    password: { type: "String", allowNull: true, SystemGenerated: "true", hidden: true },
                    lastAccess: { type: "DateTime", allowNull: true, SystemGenerated: "true" },
                    userRoles: {
                        relType: "HasMany",
                        target: "baasix_UserRole",
                        foreignKey: "user_Id",
                        as: "userRoles",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                        onDelete: "CASCADE",
                    },
                    avatar: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "avatar_Id",
                        as: "avatar",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["title", " - ", "originalFilename"],
                    },
                    status: {
                        type: "ENUM",
                        values: ["active", "inactive", "deleted", "suspended", "pending"],
                        allowNull: false,
                        defaultValue: "active", // Default value can be one of the allowed values
                    },
                },
                indexes: [
                    {
                        fields: ["email"],
                        unique: true,
                        name: "baasix_User_email_unique",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["phone"],
                        unique: true,
                        name: "baasix_User_phone_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Sessions",
            schema: {
                name: "Session",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    token: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        hidden: true,
                    },
                    user_Id: {
                        type: "UUID",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    expiresAt: {
                        type: "DateTime",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    ipAddress: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "IP address of the client",
                    },
                    userAgent: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "User agent string of the client",
                    },
                    type: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "default",
                        SystemGenerated: "true",
                    },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "user_Id",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        onDelete: "CASCADE",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
                indexes: [
                    {
                        fields: ["token"],
                        unique: true,
                        name: "baasix_Session_token_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Account",
            schema: {
                name: "Account",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    user_Id: {
                        type: "UUID",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    accountId: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Account ID from OAuth provider or same as user_Id for credential accounts",
                    },
                    providerId: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Provider ID (e.g., 'credential', 'google', 'github')",
                    },
                    accessToken: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "OAuth access token",
                        hidden: true,
                    },
                    refreshToken: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "OAuth refresh token",
                        hidden: true,
                    },
                    accessTokenExpiresAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    refreshTokenExpiresAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    scope: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "OAuth scope",
                    },
                    idToken: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "OAuth ID token",
                        hidden: true,
                    },
                    password: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Hashed password for credential accounts",
                        hidden: true,
                    },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "user_Id",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        onDelete: "CASCADE",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                },
                indexes: [
                    {
                        fields: ["user_Id", "providerId"],
                        name: "baasix_Account_user_provider",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Verification",
            schema: {
                name: "Verification",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    identifier: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Email or other identifier for verification",
                    },
                    value: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Verification token or code",
                        hidden: true,
                    },
                    expiresAt: {
                        type: "DateTime",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                },
                indexes: [
                    {
                        fields: ["identifier"],
                        name: "baasix_Verification_identifier",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_File",
            schema: {
                name: "File",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    title: { type: "String", SystemGenerated: "true" },
                    filename: { type: "String", allowNull: false, SystemGenerated: "true" },
                    originalFilename: { type: "String", allowNull: false, SystemGenerated: "true" },
                    type: { type: "String", allowNull: false, SystemGenerated: "true" },
                    folder: { type: "String", allowNull: true, SystemGenerated: "true" },
                    size: { type: "Integer", allowNull: false, SystemGenerated: "true" },
                    description: { type: "Text", SystemGenerated: "true" },
                    storage: { type: "String", allowNull: false, SystemGenerated: "true" },
                    // Physical storage folder PREFIX (e.g. "tenants/t1/users/u1"). The full
                    // storage key = storage_folder + "/" + filename. NULL means the file is
                    // still in the legacy flat layout (filename holds the whole key) — this
                    // also serves as the migration "not yet migrated" / resume marker.
                    storage_folder: { type: "String", allowNull: true, SystemGenerated: "true" },
                    width: { type: "Integer", SystemGenerated: "true" },
                    height: { type: "Integer", SystemGenerated: "true" },
                    metadata: { type: "JSON", SystemGenerated: "true" },
                    userCreated_Id: { type: "UUID", SystemGenerated: "true" },
                    userCreated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userCreated_Id",
                        as: "userCreated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    userUpdated_Id: { type: "UUID", SystemGenerated: "true" },
                    userUpdated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userUpdated_Id",
                        as: "userUpdated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    isPublic: {
                        type: "Boolean",
                        defaultValue: false,
                        allowNull: false,
                        description: "If true, asset is publicly accessible regardless of tenant",
                    },
                },
            },
        },
        {
            collectionName: "baasix_Tasks",
            schema: {
                name: "Tasks",
                fields: {
                    id: {
                        type: "Integer",
                        primaryKey: true,
                        defaultValue: { type: "AUTOINCREMENT" },
                        SystemGenerated: "true",
                    },
                    userCreated_Id: { type: "UUID", SystemGenerated: "true" },
                    userCreated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userCreated_Id",
                        as: "userCreated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    userUpdated_Id: { type: "UUID", SystemGenerated: "true" },
                    userUpdated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userUpdated_Id",
                        as: "userUpdated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    status: {
                        type: "ENUM",
                        allowNull: true,
                        defaultValue: "draft",
                        values: ["published", "draft", "archived"],
                        SystemGenerated: "true",
                    },
                    task_status: {
                        type: "ENUM",
                        allowNull: false,
                        defaultValue: "Not started",
                        values: ["Not started", "Running", "Completed", "Error"],
                    },
                    type: { type: "String", allowNull: false },
                    attachment: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "attachment_id",
                        as: "attachment",
                        description: "M2O",
                        onDelete: "SET NULL",
                        onUpdate: "SET NULL",
                        showAs: ["originalFilename"],
                    },
                    scheduled_time: {
                        type: "DateTime",
                        allowNull: false,
                        SystemGenerated: "true",
                        defaultValue: { type: "NOW" },
                    },
                    attachment_id: { type: "UUID", allowNull: true, SystemGenerated: true },
                    task_data: { type: "JSON", allowNull: true },
                    result_data: { type: "JSON" },
                    error_data: { type: "JSON", allowNull: true },
                    max_retries: {
                        type: "Integer",
                        allowNull: false,
                        defaultValue: 0,
                        description: "Maximum number of automatic retries if task stalls (0 = no retry)",
                    },
                    retry_count: {
                        type: "Integer",
                        allowNull: false,
                        defaultValue: 0,
                        SystemGenerated: "true",
                        description: "Current retry count (auto-incremented on stall recovery)",
                    },
                    started_at: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Timestamp when task was last set to Running (for stall detection)",
                    },
                    tenant_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Tenant identifier for multi-tenant isolation",
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O relationship to tenant",
                        showAs: ["name"],
                    },
                },
                timestamps: true,
                paranoid: false,
                usertrack: true,
                indexes: [
                    { fields: ["task_status", "scheduled_time"], name: "idx_tasks_status_schedule" },
                    { fields: ["task_status", "started_at"], name: "idx_tasks_status_started" },
                ],
            },
        },
        {
            collectionName: "baasix_EmailLog",
            schema: {
                name: "EmailLog",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    email: { type: "String", allowNull: false, SystemGenerated: "true" },
                    subject: { type: "String", allowNull: false, SystemGenerated: "true" },
                    templateName: { type: "String", SystemGenerated: "true" },
                    sender: { type: "String", SystemGenerated: "true" },
                    status: { type: "String", SystemGenerated: "true" },
                    messageId: { type: "String", SystemGenerated: "true" },
                    errorMessage: { type: "Text", SystemGenerated: "true" },
                },
            },
        },
        {
            collectionName: "baasix_AuditLog",
            schema: {
                name: "AuditLog",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    type: { type: "String", allowNull: false, SystemGenerated: "true", defaultValue: "data" },
                    entity: { type: "String", allowNull: false, SystemGenerated: "true" },
                    entityId: { type: "String", allowNull: true, SystemGenerated: "true" },
                    action: { type: "String", allowNull: false, SystemGenerated: "true" },
                    changes: { type: "JSON", SystemGenerated: "true" },
                    ipaddress: { type: "String", SystemGenerated: "true" },
                    userId: { type: "UUID", SystemGenerated: "true" },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userId",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
                indexes: [
                    { fields: ["createdAt"], name: "idx_auditlog_createdat" },
                    { fields: ["createdAt", "action"], name: "idx_auditlog_createdat_action" },
                    { fields: ["entity", "entityId"], name: "idx_auditlog_entity" },
                ],
            },
        },
        {
            collectionName: "baasix_Notification",
            schema: {
                name: "Notification",
                timestamps: true,
                realtime: {
                    enabled: true,
                    actions: ["insert", "update", "delete"]
                },
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    type: { type: "String", allowNull: false, SystemGenerated: "true" },
                    title: { type: "String", allowNull: false, SystemGenerated: "true" },
                    message: { type: "Text", allowNull: true, SystemGenerated: "true" },
                    seen: { type: "Boolean", allowNull: true, defaultValue: false, SystemGenerated: "true" },
                    data: { type: "JSONB", SystemGenerated: "true" },
                    userId: { type: "UUID", allowNull: false, SystemGenerated: "true" },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userId",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
            },
        },
        {
            collectionName: "baasix_Settings",
            schema: {
                name: "Settings",
                timestamps: true,
                fields: {
                    id: {
                        type: "Integer",
                        primaryKey: true,
                        defaultValue: { type: "AUTOINCREMENT" },
                        SystemGenerated: "true",
                    },
                    tenant_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Tenant ID for tenant-specific settings. NULL for global settings.",
                    },
                    // Core branding fields
                    project_name: {
                        type: "String",
                        allowNull: false,
                        defaultValue: "Baasix Project",
                        SystemGenerated: "true",
                    },
                    title: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "Baasix Project",
                        SystemGenerated: "true",
                        description: "Application title for display purposes",
                    },
                    project_url: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    app_url: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Application URL for frontend access",
                    },
                    project_color: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    secondary_color: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "#f0f0f0",
                        SystemGenerated: "true",
                        description: "Secondary brand color",
                    },
                    description: {
                        type: "Text",
                        allowNull: true,
                        defaultValue: "Powered by Baasix",
                        SystemGenerated: "true",
                        description: "Application description for SEO and branding",
                    },
                    keywords: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "cms, headless, api",
                        SystemGenerated: "true",
                        description: "SEO keywords",
                    },
                    // Logo and icon fields
                    project_logo_light_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    project_logo_dark_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    project_logo_full_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    project_logo_transparent_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    project_favicon_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    project_icon_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    email_icon_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    // Email settings
                    email_signature: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    from_email_name: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "Baasix",
                        SystemGenerated: "true",
                        description: "From name for emails",
                    },
                    // SMTP Configuration
                    smtp_enabled: {
                        type: "Boolean",
                        allowNull: false,
                        defaultValue: false,
                        SystemGenerated: "true",
                        description: "Enable custom SMTP configuration",
                    },
                    smtp_host: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "SMTP server host",
                    },
                    smtp_port: {
                        type: "Integer",
                        allowNull: true,
                        defaultValue: 587,
                        SystemGenerated: "true",
                        description: "SMTP server port",
                    },
                    smtp_secure: {
                        type: "Boolean",
                        allowNull: false,
                        defaultValue: false,
                        SystemGenerated: "true",
                        description: "Use secure SMTP connection",
                    },
                    smtp_user: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "SMTP username",
                    },
                    smtp_pass: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "SMTP password",
                    },
                    smtp_from_address: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "SMTP from email address",
                    },
                    // Localization settings
                    timezone: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "UTC",
                        SystemGenerated: "true",
                        description: "Default timezone",
                    },
                    language: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "en",
                        SystemGenerated: "true",
                        description: "Default language",
                    },
                    date_format: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "YYYY-MM-DD",
                        SystemGenerated: "true",
                        description: "Default date format",
                    },
                    currency: {
                        type: "String",
                        allowNull: true,
                        defaultValue: "USD",
                        SystemGenerated: "true",
                        description: "Default currency",
                    },
                    // Session limit settings
                    mobile_session_limit: {
                        type: "Integer",
                        allowNull: true,
                        defaultValue: -1,
                        SystemGenerated: "true",
                        description: "Maximum number of mobile sessions per user. -1 or null for unlimited, 0 to disable mobile sessions.",
                    },
                    web_session_limit: {
                        type: "Integer",
                        allowNull: true,
                        defaultValue: -1,
                        SystemGenerated: "true",
                        description: "Maximum number of web sessions per user. -1 or null for unlimited, 0 to disable web sessions.",
                    },
                    session_limit_roles: {
                        type: "JSON",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Array of role IDs to which session limits apply. If null or empty, limits apply to all roles except administrator.",
                    },
                    // Additional configuration fields
                    metadata: {
                        type: "JSON",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Additional metadata configuration",
                    },
                    modules: {
                        type: "JSON",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Module configuration and settings",
                    },
                    // Relations
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        onDelete: "CASCADE",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    project_logo_light: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_logo_light_Id",
                        as: "project_logo_light",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    project_logo_dark: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_logo_dark_Id",
                        as: "project_logo_dark",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    project_logo_full: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_logo_full_Id",
                        as: "project_logo_full",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    project_logo_transparent: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_logo_transparent_Id",
                        as: "project_logo_transparent",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    project_favicon: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_favicon_Id",
                        as: "project_favicon",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    project_icon: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "project_icon_Id",
                        as: "project_icon",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                    email_icon: {
                        relType: "BelongsTo",
                        target: "baasix_File",
                        foreignKey: "email_icon_Id",
                        as: "email_icon",
                        SystemGenerated: "true",
                        onDelete: "RESTRICT",
                        showAs: ["originalFilename"],
                    },
                },
                indexes: [
                    {
                        fields: ["tenant_Id"],
                        unique: false,
                        name: "baasix_Settings_tenant_Id",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Invite",
            schema: {
                name: "Invite",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    email: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Email address of the invitee",
                    },
                    role_Id: {
                        type: "UUID",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Role to assign when invitation is accepted",
                    },
                    tenant_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Tenant for which the invitation is valid",
                    },
                    token: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Unique token for invitation",
                    },
                    status: {
                        type: "ENUM",
                        values: ["pending", "accepted", "expired", "revoked"],
                        defaultValue: "pending",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Current status of the invitation",
                    },
                    expiresAt: {
                        type: "DateTime",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "When the invitation expires",
                    },
                    invitedBy_Id: {
                        type: "UUID",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "User who created the invitation",
                    },
                    acceptedBy_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "User who accepted the invitation (if applicable)",
                    },
                    acceptedAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "When the invitation was accepted",
                    },
                    inviter: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "invitedBy_Id",
                        as: "inviter",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "acceptedBy_Id",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    role: {
                        relType: "BelongsTo",
                        target: "baasix_Role",
                        foreignKey: "role_Id",
                        as: "role",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                },
                indexes: [
                    {
                        fields: ["token"],
                        unique: true,
                        name: "baasix_Invite_token_unique",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["email", "tenant_Id", "status"],
                        name: "baasix_Invite_email_tenant_status_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_UserPreference",
            schema: {
                name: "User Preferences",
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        allowNull: false,
                    },
                    userId: {
                        type: "UUID",
                        allowNull: true,
                        description: "ID of the user this preference belongs to",
                    },
                    user: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userId",
                        as: "user",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    collectionName: {
                        type: "String",
                        allowNull: false,
                        maxLength: 255,
                        description: "The collection these preferences apply to",
                    },
                    preferenceType: {
                        type: "ENUM",
                        allowNull: false,
                        values: ["columns", "filters", "sorting", "pagination"],
                        description: "Type of preference stored",
                    },
                    preferenceData: {
                        type: "JSON",
                        allowNull: false,
                        description: "JSON data containing the preference settings",
                    },
                    isDefault: {
                        type: "Boolean",
                        allowNull: false,
                        defaultValue: true,
                        description: "Whether this is the default preference for this user and collection",
                    },
                    name: {
                        type: "String",
                        allowNull: true,
                        maxLength: 100,
                        description: "Optional name for saved preference (for future use with multiple saved views)",
                    },
                },
                timestamps: true,
                usertrack: true,
                paranoid: false,
            },
        },
        {
            collectionName: "baasix_Workflow",
            schema: {
                name: "Workflow",
                timestamps: true,
                paranoid: true,
                usertrack: true,
                fields: {
                    id: {
                        type: "String",
                        primaryKey: true,
                        allowNull: false,
                        SystemGenerated: "true",
                        maxLength: 100,
                        description: "Workflow ID (human-readable slug)",
                    },
                    name: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Workflow name",
                    },
                    description: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Workflow description",
                    },
                    status: {
                        type: "ENUM",
                        values: ["active", "inactive", "draft"],
                        defaultValue: "draft",
                        SystemGenerated: "true",
                        description: "Workflow status",
                    },
                    trigger_type: {
                        type: "ENUM",
                        values: ["manual", "webhook", "schedule", "hook"],
                        defaultValue: "manual",
                        SystemGenerated: "true",
                        description: "How the workflow is triggered",
                    },
                    trigger_cron: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Cron expression for schedule trigger",
                    },
                    trigger_webhook_path: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Webhook path for webhook trigger",
                    },
                    trigger_webhook_method: {
                        type: "ENUM",
                        values: ["GET", "POST", "PUT", "PATCH", "DELETE"],
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "HTTP method for webhook trigger",
                    },
                    trigger_hook_collection: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Collection name for hook trigger",
                    },
                    trigger_hook_action: {
                        type: "ENUM",
                        values: [
                            "items.read",
                            "items.read.one",
                            "items.create",
                            "items.update",
                            "items.delete",
                            "items.read.after",
                            "items.read.one.after",
                            "items.create.after",
                            "items.update.after",
                            "items.delete.after",
                        ],
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Hook action for hook trigger",
                    },
                    flow_data: {
                        type: "JSONB",
                        defaultValue: { nodes: [], edges: [] },
                        SystemGenerated: "true",
                        description: "React Flow diagram data",
                    },
                    variables: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Global workflow variables",
                    },
                    options: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Additional workflow options",
                    },
                    allowed_roles: {
                        type: "JSON",
                        allowNull: true,
                        defaultValue: [],
                        SystemGenerated: "true",
                        description: "Array of role IDs allowed to execute this workflow (applies to manual and hook triggers only)",
                    },
                    userCreated_Id: { type: "UUID", SystemGenerated: "true" },
                    userCreated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userCreated_Id",
                        as: "userCreated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    userUpdated_Id: { type: "UUID", SystemGenerated: "true" },
                    userUpdated: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "userUpdated_Id",
                        as: "userUpdated",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName"],
                    },
                    executions: {
                        relType: "HasMany",
                        target: "baasix_WorkflowExecution",
                        foreignKey: "workflow_Id",
                        as: "executions",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                },
                indexes: [
                    {
                        fields: ["trigger_webhook_path", "trigger_webhook_method"],
                        name: "baasix_Workflow_webhook_idx",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["trigger_hook_collection", "trigger_hook_action"],
                        name: "baasix_Workflow_hook_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_WorkflowExecution",
            schema: {
                name: "WorkflowExecution",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    workflow_Id: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        maxLength: 100,
                    },
                    workflow: {
                        relType: "BelongsTo",
                        target: "baasix_Workflow",
                        foreignKey: "workflow_Id",
                        as: "workflow",
                        SystemGenerated: "true",
                        description: "M2O",
                        onDelete: "CASCADE",
                        showAs: ["name"],
                    },
                    status: {
                        type: "ENUM",
                        values: ["queued", "running", "completed", "failed", "cancelled"],
                        defaultValue: "queued",
                        SystemGenerated: "true",
                    },
                    trigger_data: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Data that triggered the workflow",
                    },
                    context_data: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Execution context and variables",
                    },
                    result_data: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Final result of workflow execution",
                    },
                    errorMessage: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    startedAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    completedAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    durationMs: {
                        type: "Integer",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Execution duration in milliseconds",
                    },
                    tenant_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    triggered_by_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    triggered_by: {
                        relType: "BelongsTo",
                        target: "baasix_User",
                        foreignKey: "triggered_by_Id",
                        as: "triggered_by",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["fullName", " (", "email", ")"],
                    },
                    logs: {
                        relType: "HasMany",
                        target: "baasix_WorkflowExecutionLog",
                        foreignKey: "execution_Id",
                        as: "logs",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                },
                indexes: [
                    {
                        fields: ["workflow_Id", "status"],
                        name: "baasix_WorkflowExecution_workflow_status_idx",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["tenant_Id", "createdAt"],
                        name: "baasix_WorkflowExecution_tenant_created_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_WorkflowExecutionLog",
            schema: {
                name: "WorkflowExecutionLog",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    execution_Id: {
                        type: "UUID",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    execution: {
                        relType: "BelongsTo",
                        target: "baasix_WorkflowExecution",
                        foreignKey: "execution_Id",
                        as: "execution",
                        SystemGenerated: "true",
                        description: "M2O",
                        onDelete: "CASCADE",
                    },
                    nodeId: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "React Flow node ID",
                    },
                    nodeType: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Node type (http, transform, condition, etc.)",
                    },
                    nodeLabel: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "User-defined node label",
                    },
                    status: {
                        type: "ENUM",
                        values: ["pending", "running", "success", "failed", "skipped"],
                        defaultValue: "pending",
                        SystemGenerated: "true",
                    },
                    inputData: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                    },
                    outputData: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                    },
                    errorMessage: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                    durationMs: {
                        type: "Integer",
                        allowNull: true,
                        SystemGenerated: "true",
                    },
                },
                indexes: [
                    {
                        fields: ["execution_Id"],
                        name: "baasix_WorkflowExecutionLog_execution_Id_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Migration",
            schema: {
                name: "Migration",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    version: {
                        type: "String",
                        allowNull: false,
                        unique: true,
                        SystemGenerated: "true",
                        description: "Migration version identifier (e.g., '0.1.0-alpha.7', '20240101_001')",
                    },
                    name: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Human-readable migration name",
                    },
                    description: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Detailed description of what this migration does",
                    },
                    type: {
                        type: "ENUM",
                        values: ["system", "schema", "data", "custom"],
                        defaultValue: "custom",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Type of migration: system (core updates), schema (database structure), data (data transformations), custom (user-defined)",
                    },
                    status: {
                        type: "ENUM",
                        values: ["pending", "running", "completed", "failed", "rolled_back"],
                        defaultValue: "pending",
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    batch: {
                        type: "Integer",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Migration batch number for grouping migrations run together",
                    },
                    executedAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "When the migration was successfully executed",
                    },
                    executionTimeMs: {
                        type: "Integer",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Time taken to execute the migration in milliseconds",
                    },
                    errorMessage: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Error message if migration failed",
                    },
                    errorStack: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Error stack trace if migration failed",
                    },
                    metadata: {
                        type: "JSONB",
                        defaultValue: {},
                        SystemGenerated: "true",
                        description: "Additional metadata about the migration (affected tables, records modified, etc.)",
                    },
                    checksum: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Checksum of migration script for integrity verification",
                    },
                    canRollback: {
                        type: "Boolean",
                        defaultValue: false,
                        SystemGenerated: "true",
                        description: "Whether this migration can be rolled back",
                    },
                    rolledBackAt: {
                        type: "DateTime",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "When the migration was rolled back (if applicable)",
                    },
                },
                indexes: [
                    {
                        fields: ["version"],
                        unique: true,
                        name: "baasix_Migration_version_unique",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["status"],
                        name: "baasix_Migration_status_idx",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["batch"],
                        name: "baasix_Migration_batch_idx",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["executedAt"],
                        name: "baasix_Migration_executedAt_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Template",
            schema: {
                name: "Template",
                timestamps: true,
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    type: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "The type of email template (e.g., inviteNewUser, passwordReset, or custom types)",
                    },
                    subject: {
                        type: "String",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Email subject line (supports Liquid templating)",
                    },
                    body: {
                        type: "HTML",
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Email body content (supports Liquid templating)",
                    },
                    tenant_Id: {
                        type: "UUID",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Tenant ID for tenant-specific templates. NULL means default template.",
                    },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    isActive: {
                        type: "Boolean",
                        defaultValue: true,
                        allowNull: false,
                        SystemGenerated: "true",
                        description: "Whether this template is active",
                    },
                    description: {
                        type: "Text",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "Description of the template and its purpose",
                    },
                },
                indexes: [
                    {
                        fields: ["tenant_Id", "type"],
                        unique: true,
                        nullsNotDistinct: true,
                        name: "baasix_Template_tenant_type_unique",
                        SystemGenerated: "true",
                    },
                    {
                        fields: ["type"],
                        name: "baasix_Template_type_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Page",
            schema: {
                name: "Page",
                timestamps: true,
                usertrack: true,
                realtime: { enabled: true, actions: ["insert", "update", "delete"] },
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    name: { type: "String", allowNull: false, SystemGenerated: "true" },
                    slug: { type: "String", allowNull: false, SystemGenerated: "true" },
                    icon: {
                        type: "String",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "lucide icon name",
                    },
                    description: { type: "Text", allowNull: true, SystemGenerated: "true" },
                    parent_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    parent: {
                        relType: "BelongsTo",
                        target: "baasix_Page",
                        foreignKey: "parent_Id",
                        as: "parent",
                        onDelete: "SET NULL",
                        SystemGenerated: "true",
                        description: "M2O self",
                        showAs: ["name"],
                    },
                    sort: { type: "Integer", allowNull: false, defaultValue: 0, SystemGenerated: "true" },
                    isPublic: { type: "Boolean", allowNull: false, defaultValue: false, SystemGenerated: "true" },
                    enabled: { type: "Boolean", allowNull: false, defaultValue: true, SystemGenerated: "true" },
                    options: { type: "JSON", allowNull: true, SystemGenerated: "true" },
                    roles: { type: "JSON", allowNull: true, SystemGenerated: "true", description: "role ids allowed to see this page in menus; null = all" },
                    tenant_Id: { type: "UUID", allowNull: true, SystemGenerated: "true" },
                    tenant: {
                        relType: "BelongsTo",
                        target: "baasix_Tenant",
                        foreignKey: "tenant_Id",
                        as: "tenant",
                        onDelete: "CASCADE",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    blocks: {
                        relType: "HasMany",
                        target: "baasix_Block",
                        foreignKey: "page_Id",
                        as: "blocks",
                        SystemGenerated: "true",
                        description: "M2O Alias",
                    },
                },
                indexes: [
                    {
                        fields: ["tenant_Id", "slug"],
                        unique: true,
                        nullsNotDistinct: true,
                        name: "baasix_Page_tenant_slug_unique",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
        {
            collectionName: "baasix_Block",
            schema: {
                name: "Block",
                timestamps: true,
                usertrack: true,
                realtime: { enabled: true, actions: ["insert", "update", "delete"] },
                fields: {
                    id: {
                        type: "UUID",
                        primaryKey: true,
                        defaultValue: { type: "UUIDV4" },
                        SystemGenerated: "true",
                    },
                    page_Id: { type: "UUID", allowNull: false, SystemGenerated: "true" },
                    page: {
                        relType: "BelongsTo",
                        target: "baasix_Page",
                        foreignKey: "page_Id",
                        as: "page",
                        onDelete: "CASCADE",
                        SystemGenerated: "true",
                        description: "M2O",
                        showAs: ["name"],
                    },
                    type: {
                        type: "ENUM",
                        values: ["table", "form", "details", "kanban", "calendar", "chart", "cardlist", "map", "markdown", "filter", "buttons", "media", "feed", "iframe", "upload", "code", "geochart"],
                        allowNull: false,
                        SystemGenerated: "true",
                    },
                    collection: { type: "String", allowNull: true, SystemGenerated: "true" },
                    position: {
                        type: "JSON",
                        allowNull: true,
                        SystemGenerated: "true",
                        description: "{row, col, span}",
                    },
                    config: { type: "JSON", allowNull: true, SystemGenerated: "true" },
                    configVersion: {
                        type: "Integer",
                        allowNull: false,
                        defaultValue: 1,
                        SystemGenerated: "true",
                    },
                },
                indexes: [
                    {
                        fields: ["page_Id"],
                        unique: false,
                        name: "baasix_Block_page_idx",
                        SystemGenerated: "true",
                    },
                ],
            },
        },
    ],
};
export default { schemas: systemSchemas.schemas };
//# sourceMappingURL=systemschema.js.map