import { defineNuxtModule, useLogger } from 'nuxt/kit'
import { defu } from 'defu'

export interface SaasConfig {
  name?: string
  enableMagicLink?: boolean
  enableOrganizations?: boolean
  enablePushNotifications?: boolean
}

const logger = useLogger('HarmonicSaaS')

export default defineNuxtModule<SaasConfig>({
  meta: {
    name: 'saas',
    configKey: 'saas'
  },
  moduleDependencies: {
    '@nuxt/ui': {
      version: '>=4'
    }
  },
  defaults: {
    enableMagicLink: true,
    enableOrganizations: false,
    enablePushNotifications: false
  },
  setup(options, nuxt) {
    logger.info('Loading SaaS config:', options)

    nuxt.options.runtimeConfig.public.saas = defu(nuxt.options.runtimeConfig.public.saas || {}, options)
  }
})
