import request from './request';
import type {
  LoginRequest,
  LoginResponse,
  RefreshTokenResponse,
  User,
  RegisterRequest,
} from '@media-manager/shared';

export const authApi = {
  login(data: LoginRequest): Promise<LoginResponse> {
    return request.post('/api/auth/login', data);
  },

  register(data: RegisterRequest): Promise<{ message: string; user: User }> {
    return request.post('/api/auth/register', data);
  },

  refresh(refreshToken: string): Promise<RefreshTokenResponse> {
    return request.post('/api/auth/refresh', { refreshToken });
  },

  logout(refreshToken: string): Promise<void> {
    return request.post('/api/auth/logout', { refreshToken });
  },

  getMe(): Promise<User> {
    return request.get('/api/auth/me');
  },

  changePassword(oldPassword: string, newPassword: string): Promise<void> {
    return request.put('/api/auth/password', { oldPassword, newPassword });
  },

  updateProfile(data: { nickname?: string; email?: string; avatarUrl?: string }): Promise<User> {
    return request.put('/api/auth/profile', data);
  },
};
