import axios, { type AxiosInstance } from 'axios';
import { buildQueryString, httpGet } from '@utils/HttpUtils'
import { IClientAuthentication, IClientSignatureRequest, IClientSignatureResponse } from '@business-logic/types/Authentication';


const adminServiceUrl = process.env.ADMIN_SERVICE_API_URL || '';

const axiosInstance: AxiosInstance = axios.create({
    baseURL: adminServiceUrl,
    headers: {'Content-Type': 'application/json'}
});

const INSURANCE_SERVICE_ROUTE = 'insurance';

export const getClientAuthByClientTag = async (clientTag: string): Promise<IClientAuthentication> => {
    return await httpGet<IClientAuthentication>(axiosInstance, `${INSURANCE_SERVICE_ROUTE}/client-info?clientTag=${clientTag}`);
}
export const getClientSignature = async (request: IClientSignatureRequest): Promise<IClientSignatureResponse> => {
    const params = buildQueryString(request);
    return await httpGet<IClientSignatureResponse>(axiosInstance, `${INSURANCE_SERVICE_ROUTE}/signature?${params.toString()}`);
}