/** * Copyright 2024-2026 Wingify Software Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { dynamic } from '../../../types/Common'; import { Constants } from '../../../constants'; /** * Represents a model for global HTTP requests configuration. * This class encapsulates all necessary details such as URL, query parameters, body, headers, * timeout settings, and development mode flag. */ export class GlobalRequestModel { private url: string; // Base URL of the HTTP request private timeout = Constants.EVENTS_CALL_TIMEOUT; // Default timeout for the HTTP request in milliseconds private query: Record; // Query parameters for the HTTP request private body: Record; // Body of the HTTP request private headers: Record; // HTTP headers private isDevelopmentMode: boolean; // Flag to indicate if the request is in development mode /** * Constructs an instance of the GlobalRequestModel. * @param url The base URL of the HTTP request. * @param query Query parameters as a record of key-value pairs. * @param body Body of the request as a record of key-value pairs. * @param headers HTTP headers as a record of key-value pairs. */ constructor( url: string, query: Record, body: Record, headers: Record, ) { this.url = url; this.query = query; this.body = body; this.headers = headers; } /** * Sets the query parameters for the HTTP request. * @param query A record of key-value pairs representing the query parameters. */ setQuery(query: Record): void { this.query = query; } /** * Retrieves the query parameters of the HTTP request. * @returns A record of key-value pairs representing the query parameters. */ getQuery(): Record { return this.query; } /** * Sets the body of the HTTP request. * @param body A record of key-value pairs representing the body content. */ setBody(body: Record): void { this.body = body; } /** * Retrieves the body of the HTTP request. * @returns A record of key-value pairs representing the body content. */ getBody(): Record { return this.body; } /** * Sets the base URL of the HTTP request. * @param url The base URL as a string. */ setBaseUrl(url: string): void { this.url = url; } /** * Retrieves the base URL of the HTTP request. * @returns The base URL as a string. */ getBaseUrl(): string { return this.url; } /** * Sets the timeout duration for the HTTP request. * @param timeout Timeout in milliseconds. */ setTimeout(timeout: number): void { this.timeout = timeout; } /** * Retrieves the timeout duration of the HTTP request. * @returns Timeout in milliseconds. */ getTimeout(): number { return this.timeout; } /** * Sets the HTTP headers for the request. * @param headers A record of key-value pairs representing the HTTP headers. */ setHeaders(headers: Record): void { this.headers = headers; } /** * Retrieves the HTTP headers of the request. * @returns A record of key-value pairs representing the HTTP headers. */ getHeaders(): Record { return this.headers; } /** * Sets the development mode status for the request. * @param isDevelopmentMode Boolean flag indicating if the request is in development mode. */ setDevelopmentMode(isDevelopmentMode: boolean): void { this.isDevelopmentMode = isDevelopmentMode; } /** * Retrieves the development mode status of the request. * @returns Boolean indicating if the request is in development mode. */ getDevelopmentMode(): boolean { return this.isDevelopmentMode; } }