"""
Create imunify360-merged-nonprivileged.config with settings needed by non-root processes.
"""
import logging

from defence360agent.contracts.config import Merger

logger = logging.getLogger(__name__)


def migrate(migrator, database, fake=False, **kwargs):
    if fake:
        return

    try:
        # Trigger a full config merge which will:
        # - Write nonprivileged settings to imunify360-merged-nonprivileged.config
        # - Write all settings to imunify360-merged.config
        Merger.update_merged_config()
        logger.info("Successfully created nonprivileged config")
    except Exception as exc:
        logger.error(
            "Failed to create nonprivileged config: %s",
            exc,
        )


def rollback(migrator, database, fake=False, **kwargs):
    pass
