import { adminProcedure, createTRPCRouter } from "../trpc.js";
import {
  clearStoredRuntimeSecrets,
  getAiConfiguredStatus,
  getSystemSettingsView,
  testSettingsAiConnection,
  testSettingsGeminiConnection,
  testSettingsSmtpConnection,
  updateSystemSettings,
} from "./settings-procedure-support.js";
import { settingsUpdateInputSchema } from "./settings-support.js";

export const settingsRouter = createTRPCRouter({
  getSystemSettings: adminProcedure.query(({ ctx }) => getSystemSettingsView(ctx)),

  updateSystemSettings: adminProcedure
    .input(settingsUpdateInputSchema)
    .mutation(({ ctx, input }) => updateSystemSettings(ctx, input)),

  clearStoredRuntimeSecrets: adminProcedure.mutation(({ ctx }) => clearStoredRuntimeSecrets(ctx)),

  testAiConnection: adminProcedure.mutation(({ ctx }) => testSettingsAiConnection(ctx)),

  testSmtpConnection: adminProcedure.mutation(({ ctx }) => testSettingsSmtpConnection(ctx)),

  testGeminiConnection: adminProcedure.mutation(({ ctx }) => testSettingsGeminiConnection(ctx)),

  getAiConfigured: adminProcedure.query(({ ctx }) => getAiConfiguredStatus(ctx)),
});
