import { RowDataPacket } from "mysql2";
import DB from "../../../config/database/db";
import CONSTANTS from "../../../config/constants";

const whatsappLedgerDB: any = {};

whatsappLedgerDB.getRentDueByClientIdAndDate = async ({
  clientId,
  rentDate
}: any) => {
  const query =
    "Select T.name as tenantName, T.mobile as tenantMobile, P.name as propName, D.amount from Dues as D join Tenants as T on T.id = D.tenantId join Properties as P on P.id = D.propId where D.clientId = ? and D.type = ? and DATE(D.createdAt) = ?";
  const data = [clientId, CONSTANTS.DUES_TYPES.RENT, rentDate];
  const [rows] = await DB.execute<RowDataPacket[]>(query, data);
  if (rows?.length > 0) return rows;
  else return false;
};

export default whatsappLedgerDB;