interface SQLDeleteGenReturn {
    query: string;
    values: string[];
}

/**
 * # SQL Delete Generator
 */
export default function sqlDeleteGenerator({
    tableName,
    data,
    dbFullName,
}: {
    data: any;
    tableName: string;
    dbFullName?: string;
}): SQLDeleteGenReturn | undefined {
    const finalDbName = dbFullName ? `${dbFullName}.` : "";

    try {
        let queryStr = `DELETE FROM ${finalDbName}${tableName}`;

        let deleteBatch: string[] = [];
        let queryArr: string[] = [];

        Object.keys(data).forEach((ky) => {
            deleteBatch.push(`${ky}=?`);
            queryArr.push(data[ky]);
        });
        queryStr += ` WHERE ${deleteBatch.join(" AND ")}`;

        return {
            query: queryStr,
            values: queryArr,
        };
    } catch (/** @type {any} */ error: any) {
        console.log(`SQL delete gen ERROR: ${error.message}`);
        return undefined;
    }
}
