import { axiosInstance } from '../../config/api';
import { LOGIN, PROFILE } from './loginActionTypes';

export const login = (data) => ({
  type: LOGIN,
  payload: axiosInstance.post('/auth/login', data),
});

export const profile = () => ({
  type: PROFILE,
  payload: axiosInstance.get('/users/me'),
});

// export const login = (data) => {
//   // Determine user type based on email
//   const isSuperAdmin = data.email === 'admin@gmail.com';
//   const userRole = isSuperAdmin ? 'SUPER_ADMIN' : 'CLINIC_ADMIN';
//   const userId = isSuperAdmin ? 'super-admin-123' : 'clinic-admin-123';
  
//   // Store token and user type in localStorage to simulate a real login
//   localStorage.setItem('token', `mock-jwt-token-for-${isSuperAdmin ? 'super' : 'clinic'}-admin`);
//   localStorage.setItem('userType', userRole);
  
//   // Mock successful login response
//   const mockLoginResponse = {
//     data: {
//       message: 'Login successful',
//       token: `mock-jwt-token-for-${isSuperAdmin ? 'super' : 'clinic'}-admin`,
//       user: {
//         id: userId,
//         email: data.email,
//         role: userRole
//       }
//     }
//   };

//   return {
//     type: LOGIN,
//     // Use a real Promise with a slight delay to simulate network request
//     payload: new Promise(resolve => setTimeout(() => resolve(mockLoginResponse), 300))
//   };
// };

// export const profile = () => {
//   // Get user type from localStorage to determine which profile to return
//   const userType = localStorage.getItem('userType') || 'CLINIC_ADMIN';
//   const isSuperAdmin = userType === 'SUPER_ADMIN';
  
//   // Create appropriate mock profile based on user type
//   let profileData;
  
//   if (isSuperAdmin) {
//     // Super Admin profile
//     profileData = {
//       id: 'super-admin-123',
//       name: 'Super Administrator',
//       email: 'admin@gmail.com',
//       role: 'SUPER_ADMIN',
//       isAdmin: true,
//       isSuperAdmin: true, // This flag identifies super admin
//       permissions: [
//         'CREATE_REC_USERS',
//         'READ_REC_USERS',
//         'DELETE_REC_USERS',
//         'SUPER_ADMIN_PERMISSION'
//       ]
//     };
//   } else {
//     // Clinic Admin profile
//     profileData = {
//       id: 'clinic-admin-123',
//       name: 'Clinic Administrator',
//       email: 'admin@clinic.com',
//       role: 'CLINIC_ADMIN',
//       isAdmin: true,
//       isSuperAdmin: false,
//       permissions: [
//         'CREATE_REC_USERS',
//         'READ_REC_USERS',
//         'DELETE_REC_USERS'
//       ],
//       clinic: {
//         id: 'clinic-123',
//         name: 'Health Plus Clinic',
//         address: '123 Medical Center Blvd',
//         city: 'Healthcare City',
//         state: 'HC',
//         zipCode: '12345',
//         phone: '555-123-4567'
//       }
//     };
//   }

//   // Create the response with the nested data structure the reducer expects
//   const mockProfileResponse = {
//     data: {
//       data: profileData
//     }
//   };

//   return {
//     type: PROFILE,
//     // Use a real Promise with a slight delay to simulate network request
//     payload: new Promise(resolve => setTimeout(() => resolve(mockProfileResponse), 300))
//   };
// };
