import { createRequire } from "node:module";
var __create = Object.create;
var __getProtoOf = Object.getPrototypeOf;
var __defProp = Object.defineProperty;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __toESM = (mod, isNodeMode, target) => {
  target = mod != null ? __create(__getProtoOf(mod)) : {};
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
  for (let key of __getOwnPropNames(mod))
    if (!__hasOwnProp.call(to, key))
      __defProp(to, key, {
        get: () => mod[key],
        enumerable: true
      });
  return to;
};
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, {
      get: all[name],
      enumerable: true,
      configurable: true,
      set: (newValue) => all[name] = () => newValue
    });
};
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
var __require = /* @__PURE__ */ createRequire(import.meta.url);

// src/config/timeback.ts
function getTimebackMode() {
  const explicit = process.env.TIMEBACK_MODE;
  if (explicit === "local" || explicit === "remote" || explicit === "disabled")
    return explicit;
  if (process.env.TIMEBACK_LOCAL === "true")
    return "local";
  if (process.env.TIMEBACK_API_CLIENT_ID)
    return "remote";
  return "disabled";
}
function isTimebackEnabled() {
  return config.timeback.mode !== "disabled";
}
function hasTimebackCredentials() {
  const { mode, onerosterApiUrl, caliperApiUrl, clientId, clientSecret, authUrl } = config.timeback;
  if (mode === "local") {
    return !!(onerosterApiUrl && caliperApiUrl);
  }
  if (mode === "remote") {
    return !!(onerosterApiUrl && clientId && clientSecret && authUrl);
  }
  return false;
}
function hasTimebackFullConfig() {
  return hasTimebackCredentials() && !!(config.timeback.courseId && config.timeback.studentId);
}
function requireTimebackCredentials() {
  if (hasTimebackCredentials())
    return config.timeback;
  const { mode, onerosterApiUrl, caliperApiUrl, clientId, clientSecret, authUrl } = config.timeback;
  if (mode === "local") {
    const missing2 = [];
    if (!onerosterApiUrl)
      missing2.push("TIMEBACK_ONEROSTER_API_URL");
    if (!caliperApiUrl)
      missing2.push("TIMEBACK_CALIPER_API_URL");
    throw new Error(`TimeBack local mode missing: ${missing2.join(", ")}`);
  }
  const missing = [];
  if (!onerosterApiUrl)
    missing.push("TIMEBACK_ONEROSTER_API_URL");
  if (!clientId)
    missing.push("TIMEBACK_API_CLIENT_ID");
  if (!clientSecret)
    missing.push("TIMEBACK_API_CLIENT_SECRET");
  if (!authUrl)
    missing.push("TIMEBACK_API_AUTH_URL");
  throw new Error(`TimeBack credentials missing: ${missing.join(", ")}`);
}
function configureTimeback(options) {
  if (options.mode) {
    config.timeback.mode = options.mode;
    process.env.TIMEBACK_MODE = options.mode;
  }
  if (options.onerosterApiUrl) {
    config.timeback.onerosterApiUrl = options.onerosterApiUrl;
    process.env.TIMEBACK_ONEROSTER_API_URL = options.onerosterApiUrl;
  }
  if (options.caliperApiUrl) {
    config.timeback.caliperApiUrl = options.caliperApiUrl;
    process.env.TIMEBACK_CALIPER_API_URL = options.caliperApiUrl;
  }
  if (options.clientId) {
    config.timeback.clientId = options.clientId;
    process.env.TIMEBACK_API_CLIENT_ID = options.clientId;
  }
  if (options.clientSecret) {
    config.timeback.clientSecret = options.clientSecret;
    process.env.TIMEBACK_API_CLIENT_SECRET = options.clientSecret;
  }
  if (options.authUrl) {
    config.timeback.authUrl = options.authUrl;
    process.env.TIMEBACK_API_AUTH_URL = options.authUrl;
  }
  if (options.courseId) {
    config.timeback.courseId = options.courseId;
    process.env.SANDBOX_TIMEBACK_COURSE_ID = options.courseId;
  }
  if (options.studentId) {
    config.timeback.studentId = options.studentId;
    process.env.SANDBOX_TIMEBACK_STUDENT_ID = options.studentId;
  }
}

// src/config/mutators.ts
function setEmbeddedMode(embedded) {
  config.embedded = embedded;
  process.env.PLAYCADEMY_EMBEDDED = embedded ? "1" : undefined;
}

// src/config/index.ts
var config = {
  embedded: process.env.PLAYCADEMY_EMBEDDED === "1",
  auth: {
    betterAuthSecret: process.env.BETTER_AUTH_SECRET || "sandbox-better-auth-secret-for-testing",
    gameJwtSecret: process.env.GAME_JWT_SECRET || "sandbox-game-jwt-secret-for-testing"
  },
  timeback: {
    mode: getTimebackMode(),
    onerosterApiUrl: process.env.TIMEBACK_ONEROSTER_API_URL,
    caliperApiUrl: process.env.TIMEBACK_CALIPER_API_URL,
    clientId: process.env.TIMEBACK_API_CLIENT_ID,
    clientSecret: process.env.TIMEBACK_API_CLIENT_SECRET,
    authUrl: process.env.TIMEBACK_API_AUTH_URL,
    courseId: process.env.SANDBOX_TIMEBACK_COURSE_ID,
    studentId: process.env.SANDBOX_TIMEBACK_STUDENT_ID
  }
};
process.env.BETTER_AUTH_SECRET = config.auth.betterAuthSecret;
process.env.GAME_JWT_SECRET = config.auth.gameJwtSecret;
export {
  setEmbeddedMode,
  requireTimebackCredentials,
  isTimebackEnabled,
  hasTimebackFullConfig,
  hasTimebackCredentials,
  configureTimeback,
  config
};
