import client from './client'
import type { TokenResponse, User } from '@/types'

export interface RegisterData {
  login: string
  password: string
  nickname: string
}

export interface LoginData {
  login: string
  password: string
}

export const authApi = {
  register: async (data: RegisterData): Promise<TokenResponse> => {
    const response = await client.post<TokenResponse>('/auth/register', data)
    return response.data
  },

  login: async (data: LoginData): Promise<TokenResponse> => {
    const response = await client.post<TokenResponse>('/auth/login', data)
    return response.data
  },

  me: async (): Promise<User> => {
    const response = await client.get<User>('/auth/me')
    return response.data
  },
}
