import { ResultSetHeader, RowDataPacket } from "mysql2";
import DB from "../config/database/db";
import whatsappTemplatesTypes from "../schemas/whatsappTemplates.schema";
import log from "../config/log";
import CONSTANTS from "../config/constants";

const whatsAppTemplateDB: any = {};

whatsAppTemplateDB.getByClientAndType = async ({
  clientId,
  provider,
  type,
  userType = CONSTANTS.USER_TYPE.TENANT
}: whatsappTemplatesTypes) => {
  const query =
    "Select * from WhatsappTemplates where clientId = ? and provider=? and type=? and userType=?";
  const data = [clientId, provider, type, userType];
  const [rows] = await DB.execute<RowDataPacket[]>(query, data);
  if (rows?.length > 0) return rows[0];
  else return false;
};



export default whatsAppTemplateDB;
