export const logAudit = async (
  db,
  {
    companyId,
    userId = null,
    action,
    entityType,
    entityId = null,
    oldData = null,
    newData = null,
    ipAddress = null,
  },
) => {
  await db.query(
    `
      INSERT INTO audit_log (
        company_id,
        user_id,
        action,
        entity_type,
        entity_id,
        old_data,
        new_data,
        ip_address
      )
      VALUES ($1, $2, $3, $4, $5, $6::jsonb, $7::jsonb, $8)
    `,
    [
      companyId,
      userId,
      action,
      entityType,
      entityId,
      oldData ? JSON.stringify(oldData) : null,
      newData ? JSON.stringify(newData) : null,
      ipAddress,
    ],
  );
};
