import connDbHandler from "../../db/conn-db-handler";
import grabDSQLConnection from "../../grab-dsql-connection";

type Param = {
    paradigm: "Full Access" | "FA" | "Read Only";
    queryString: string;
    queryValues?: string[];
};

/**
 * # DSQL user read-only DB handler
 */
export default async function DSQL_USER_DB_HANDLER({
    paradigm,
    queryString,
    queryValues,
}: Param) {
    const CONNECTION =
        paradigm == "Read Only"
            ? grabDSQLConnection({ ro: true })
            : grabDSQLConnection({ fa: true });

    try {
        return await connDbHandler(CONNECTION, queryString, queryValues);
    } catch (error: any) {
        console.log(`DSQL_USER_DB_HANDLER Error: ${error.message}`);
        return null;
    } finally {
        CONNECTION?.end();
    }
}
