import {InfisicalSDK} from "@infisical/sdk"

const client = new InfisicalSDK({
    siteUrl: "https://secrets.fedeo.io"
})



export let secrets = {

} as {
    COOKIE_SECRET: string
    JWT_SECRET: string
    PORT: number
    HOST: string
    DATABASE_URL: string
    S3_BUCKET: string
    ENCRYPTION_KEY: string
    MAILER_SMTP_HOST: string
    MAILER_SMTP_PORT: number
    MAILER_SMTP_SSL: string
    MAILER_SMTP_USER: string
    MAILER_SMTP_PASS: string
    MAILER_FROM: string
    S3_ENDPOINT: string
    S3_REGION: string
    S3_ACCESS_KEY: string
    S3_SECRET_KEY: string
    M2M_API_KEY: string
    API_BASE_URL: string
    GOCARDLESS_BASE_URL: string
    GOCARDLESS_SECRET_ID: string
    GOCARDLESS_SECRET_KEY: string
    DOKUBOX_IMAP_HOST: string
    DOKUBOX_IMAP_PORT: number
    DOKUBOX_IMAP_SECURE: boolean
    DOKUBOX_IMAP_USER: string
    DOKUBOX_IMAP_PASSWORD: string
    OPENAI_API_KEY: string
    STIRLING_API_KEY: string
}

export async function loadSecrets () {

    await client.auth().universalAuth.login({
        clientId: process.env.INFISICAL_CLIENT_ID,
        clientSecret: process.env.INFISICAL_CLIENT_SECRET,
    });

    const allSecrets = await client.secrets().listSecrets({
        environment: "dev", // stg, dev, prod, or custom environment slugs
        projectId: "39774094-2aaf-49fb-a213-d6b2c10f6144"
    });

    allSecrets.secrets.forEach(secret => {
        secrets[secret.secretKey] = secret.secretValue
    })
    console.log("✅ Secrets aus Infisical geladen");
    console.log(Object.keys(secrets).length + " Stück")
}

