import api from './api';

export interface UserProfile {
  id: string;
  userId: string;
  email: string;
  firstName: string | null;
  lastName: string | null;
  phone: string | null;
  avatar: string | null;
  city: string | null;
  state: string | null;
  country: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface UpdateUserProfileData {
  firstName?: string;
  lastName?: string;
  phone?: string;
  avatar?: string | null;
  city?: string;
  state?: string;
  country?: string;
}

interface ApiResponse<T> {
  success: boolean;
  data: T;
  message?: string;
}

export const usersService = {
  /**
   * Get current user's profile
   */
  async getMyProfile(): Promise<UserProfile> {
    const response = await api.get<ApiResponse<UserProfile>>('/users/profile/me');
    return response.data.data;
  },

  /**
   * Update current user's profile
   */
  async updateProfile(data: UpdateUserProfileData): Promise<UserProfile> {
    const response = await api.patch<ApiResponse<UserProfile>>('/users/profile/me', data);
    return response.data.data;
  },

  /**
   * Submit or resubmit profile for verification (agent only)
   */
  async submitForVerification(): Promise<{ message: string; status: string }> {
    const response = await api.post<ApiResponse<{ message: string; status: string }>>('/users/me/verification/submit');
    return response.data.data;
  },
};
