import { Body, Controller, Get, Patch, Post, UseGuards, } from "@nestjs/common"; import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags, } from "@nestjs/swagger"; import { SuperAdminGuard } from "./guards/super-admin.guard"; import { SuperAdminService } from "./super-admin.service"; import { CreateSuperAdminDto, CreateFieldExpertAdminDto, CreateRegistrarAdminDto, } from "./dto/super-admin.dto"; import { ClientDto } from "src/client/dto/create-client.dto"; import { InsurerRegisterDto, GenuineRegisterDto, LegalRegisterDto, } from "src/auth/dto/actor/register.actor.dto"; import { SystemSettingsService } from "src/system-settings/system-settings.service"; import { SystemSettingsResponseDto, UpdateSystemSettingsDto, } from "src/system-settings/dto/system-settings.dto"; import { SetExternalInquiriesLiveDto } from "src/client/dto/external-inquiries-live.dto"; @ApiTags("super-admin") @ApiBearerAuth() @UseGuards(SuperAdminGuard) @Controller("super-admin") export class SuperAdminController { constructor( private readonly superAdminService: SuperAdminService, private readonly systemSettingsService: SystemSettingsService, ) {} // ── Super-admin account management ─────────────────────────────────────── @Get("accounts") @ApiOperation({ summary: "List all super-admin accounts" }) listSuperAdmins() { return this.superAdminService.listSuperAdmins(); } @Post("accounts") @ApiOperation({ summary: "Create an additional super-admin account" }) @ApiBody({ type: CreateSuperAdminDto }) createSuperAdmin(@Body() body: CreateSuperAdminDto) { return this.superAdminService.createSuperAdmin(body); } // ── Client / insurer management ────────────────────────────────────────── @Post("clients") @ApiOperation({ summary: "Create a new insurer client", description: "Registers a new insurer (client) in the platform.", }) @ApiBody({ type: ClientDto }) createClient(@Body() body: ClientDto) { return this.superAdminService.createClient(body); } @Get("clients") @ApiOperation({ summary: "List all insurer clients" }) listClients() { return this.superAdminService.listClients(); } @Get("clients/names") @ApiOperation({ summary: "List insurer client names and IDs" }) listClientNames() { return this.superAdminService.listClientNames(); } // ── Actor registration ─────────────────────────────────────────────────── @Post("register/insurer") @ApiOperation({ summary: "Register a new insurer (company) actor" }) @ApiBody({ type: InsurerRegisterDto }) registerInsurer(@Body() body: InsurerRegisterDto) { return this.superAdminService.registerInsurer(body); } @Post("register/genuine") @ApiOperation({ deprecated: true, summary: "[DEPRECATED] Register a genuine actor", description: "Kept for legacy clients. Use the unified onboarding flow instead.", }) @ApiBody({ type: GenuineRegisterDto }) registerGenuine(@Body() body: GenuineRegisterDto) { return this.superAdminService.registerGenuine(body); } @Post("register/legal") @ApiOperation({ deprecated: true, summary: "[DEPRECATED] Register a legal actor", description: "Kept for legacy clients. Use the unified onboarding flow instead.", }) @ApiBody({ type: LegalRegisterDto }) registerLegal(@Body() body: LegalRegisterDto) { return this.superAdminService.registerLegal(body); } @Post("create-field-expert") @ApiOperation({ summary: "Create a field expert" }) @ApiBody({ type: CreateFieldExpertAdminDto }) createFieldExpert(@Body() body: CreateFieldExpertAdminDto) { return this.superAdminService.createFieldExpert(body); } @Post("create-registrar") @ApiOperation({ summary: "Create a registrar" }) @ApiBody({ type: CreateRegistrarAdminDto }) createRegistrar(@Body() body: CreateRegistrarAdminDto) { return this.superAdminService.createRegistrar(body); } // ── System settings ────────────────────────────────────────────────────── @Get("system-settings") @ApiOperation({ summary: "Get global system settings" }) @ApiResponse({ status: 200, type: SystemSettingsResponseDto }) getSystemSettings() { return this.systemSettingsService.getSettingsView(); } @Patch("system-settings") @ApiOperation({ summary: "Update global system settings" }) @ApiBody({ type: UpdateSystemSettingsDto }) @ApiResponse({ status: 200, type: SystemSettingsResponseDto }) updateSystemSettings(@Body() body: UpdateSystemSettingsDto) { return this.systemSettingsService.updateSettings(body); } @Patch("external-inquiries-live") @ApiOperation({ summary: "Enable or disable live external inquiries globally", description: "Updates `system_settings.externalApis.sandHubUseLiveApi`. When disabled, all inquiry flows use mocks.", }) @ApiBody({ type: SetExternalInquiriesLiveDto }) @ApiResponse({ status: 200, type: SystemSettingsResponseDto }) setExternalInquiriesLive(@Body() body: SetExternalInquiriesLiveDto) { return this.systemSettingsService.updateSettings({ externalApis: { sandHubUseLiveApi: body?.enabled === true }, }); } }