/**
 * Utility functions for Parking Access Control
 */

/**
 * Checks if a user has permission to access the parking module
 * @param {Object} user - The user object containing role and permissions
 * @returns {boolean} - True if user has access
 */
export const hasParkingAccess = (user) => {
  if (!user) return false;
  if (user.role === 'admin' || user.role === 'employee') return true;
  return !!user.can_fill_parking_forms;
};

/**
 * Checks if a user can manage a specific parking record
 * @param {Object} user - The user object
 * @param {Object} record - The parking record
 * @returns {boolean} - True if user can manage the record
 */
export const canManageParkingRecord = (user, record) => {
  if (!user || !record) return false;
  if (user.role === 'admin' || user.role === 'employee') return true;
  return user.client_id === record.client_id && !!user.can_fill_parking_forms;
};

/**
 * Gets the client_id to filter by for a specific user
 * @param {Object} user - The user object
 * @returns {string|null} - The client_id to filter by, or null if no filtering needed (admin) or no access
 */
export const getParkingRecordsForUser = (user) => {
  if (!user) return null;
  // Admins/Employees don't inherently strictly filter by their own client_id unless they want to
  // But for the purpose of "Default View", admins see all (null) and clients see theirs
  if (user.role === 'admin' || user.role === 'employee') return null;
  return user.client_id;
};