import { apiClient } from './api'
import type { 
  LoginCredentials, 
  RegisterData, 
  LoginResponse, 
  User,
  RefreshTokenResponse 
} from '@/types/auth'

export const authService = {
  async login(credentials: LoginCredentials): Promise<LoginResponse> {
    const response = await apiClient.post('/auth/login', {
      email: credentials.email,
      password: credentials.password
    })
    return response.data
  },

  async register(data: RegisterData): Promise<{ message: string }> {
    const response = await apiClient.post('/auth/register', data)
    return response.data
  },

  async logout(refreshToken: string): Promise<void> {
    await apiClient.post('/auth/logout', { refresh_token: refreshToken })
  },

  async refreshToken(refreshToken: string): Promise<RefreshTokenResponse> {
    const response = await apiClient.post('/auth/refresh', { 
      refresh_token: refreshToken 
    })
    return response.data
  },

  async getCurrentUser(): Promise<User> {
    const response = await apiClient.get('/users/me')
    return response.data
  }
}