import ThirdPartyNode from "supertokens-node/recipe/thirdparty";
import EmailPasswordNode from "supertokens-node/recipe/emailpassword";
import SessionNode from "supertokens-node/recipe/session";
import { TypeInput } from "supertokens-node/types";
import { AppInfoUserInput } from "supertokens-node/types";

const appInfo: AppInfoUserInput = {
  appName: "Vib'n",
  apiDomain: process.env.NEXT_PUBLIC_APP_URL || "https://app.vibnai.com",
  websiteDomain: process.env.NEXT_PUBLIC_APP_URL || "https://app.vibnai.com",
  apiBasePath: "/api/auth",
  websiteBasePath: "/auth",
};

export const backendConfig = (): TypeInput => {
  return {
    framework: "custom",
    supertokens: {
      connectionURI: process.env.SUPERTOKENS_CONNECTION_URI || "https://auth.vibnai.com",
      apiKey: process.env.SUPERTOKENS_API_KEY,
    },
    appInfo,
    recipeList: [
      ThirdPartyNode.init({
        signInAndUpFeature: {
          providers: [
            {
              config: {
                thirdPartyId: "google",
                clients: [{
                  clientId: process.env.GOOGLE_CLIENT_ID || "",
                  clientSecret: process.env.GOOGLE_CLIENT_SECRET || "",
                }],
              },
            },
            {
              config: {
                thirdPartyId: "github",
                clients: [{
                  clientId: process.env.GITHUB_CLIENT_ID || "",
                  clientSecret: process.env.GITHUB_CLIENT_SECRET || "",
                }],
              },
            },
          ],
        },
      }),
      EmailPasswordNode.init(),
      SessionNode.init(),
    ],
    isInServerlessEnv: true,
  };
};
