import { Body, Controller, Get, Patch, Post } from "@nestjs/common"; import { ApiBody, ApiOperation, ApiResponse, ApiTags, } from "@nestjs/swagger"; import { CurrentUser } from "src/decorators/user.decorator"; import { SystemSettingsResponseDto } from "src/system-settings/dto/system-settings.dto"; import { SystemSettingsService } from "src/system-settings/system-settings.service"; import { ClientService } from "./client.service"; import { ClientDto } from "./dto/create-client.dto"; import { SetExternalInquiriesLiveDto } from "./dto/external-inquiries-live.dto"; @Controller("client") @ApiTags("client-management") export class ClientController { constructor( private readonly clientService: ClientService, private readonly systemSettingsService: SystemSettingsService, ) {} @Post() async addClient(@Body() client: ClientDto) { return await this.clientService.addClient(client); } @Get() async getClient(@CurrentUser() user) { return await this.clientService.getClients(); } @Get("list") async getClientList(@CurrentUser() user) { return await this.clientService.getClientList(); } /** Toggle SandHub/Tejarat live HTTP vs mock inquiries (`system_settings.externalApis.sandHubUseLiveApi`). */ @Patch("external-inquiries-live") @ApiOperation({ summary: "Enable or disable live external inquiries", description: "Updates `system_settings.externalApis.sandHubUseLiveApi`. No auth required. Use the request examples below to switch between live Tejarat/SandHub HTTP and offline mock mode.", }) @ApiBody({ type: SetExternalInquiriesLiveDto, examples: { enableLive: { summary: "Enable live inquiries", description: "Call real SandHub/Tejarat HTTP APIs.", value: { enabled: true }, }, disableLive: { summary: "Disable live inquiries (mock mode)", description: "Use mocked inquiry responses; flows continue without external connectivity.", value: { enabled: false }, }, }, }) @ApiResponse({ status: 200, type: SystemSettingsResponseDto }) async setExternalInquiriesLive(@Body() body?: SetExternalInquiriesLiveDto) { return this.systemSettingsService.updateSettings({ externalApis: { sandHubUseLiveApi: body?.enabled === true }, }); } }