// @ts-check
import { defineConfig, envField } from 'astro/config';

import tailwindcss from '@tailwindcss/vite';

import svelte, { vitePreprocess } from '@astrojs/svelte';

import node from '@astrojs/node';

// https://astro.build/config
export default defineConfig({
  output: 'server',
  prefetch: true,
  base: process.env.BASE_PATH ?? undefined,

  security: {
    checkOrigin: false
  },

  devToolbar: {
    enabled: false
  },

  vite: {
    plugins: [tailwindcss()]
  },

  integrations: [svelte({ preprocess: vitePreprocess() })],

  env: {
    schema: {
      API_SECRET: envField.string({ context: 'server', access: 'secret', optional: true }),

      ADMIN_USER: envField.string({ context: 'server', access: 'secret', optional: true }),
      ADMIN_PASSWORD: envField.string({ context: 'server', access: 'secret', optional: true }),
      ADMIN_COOKIE: envField.string({ context: 'server', access: 'secret', default: 'muelleel' }),

      UPLOAD_PATH: envField.string({ context: 'server', access: 'secret', optional: true }),
      MAX_UPLOAD_BYTES: envField.number({ context: 'server', access: 'secret', default: 20 * 1024 * 1024 }),

      START_DATE: envField.string({ context: 'server', access: 'secret', default: '1970-01-01' }),

      WEBHOOK_ENDPOINT: envField.string({ context: 'server', access: 'secret', optional: true }),

      STATISTICS_ENDPOINT: envField.string({ context: 'server', access: 'secret', optional: true }),
      STATISTICS_INTERVAL: envField.number({ context: 'server', access: 'secret', default: 60 * 30 }),

      TEAMSPEAK_LINK: envField.string({ context: 'server', access: 'secret', default: 'http://example.com' }),
      DISCORD_LINK: envField.string({ context: 'server', access: 'secret', default: 'http://example.com' }),
      PAYPAL_LINK: envField.string({ context: 'server', access: 'secret', default: 'http://example.com' }),
      SERVER_IP: envField.string({ context: 'server', access: 'secret', default: 'http://example.com' }),

      DATABASE_URI: envField.string({ context: 'server', access: 'secret' }),

      BASE_PATH: envField.string({ context: 'server', access: 'secret', default: '/' })
    }
  },

  adapter: node({
    mode: 'standalone'
  })
});
