import { apiRequest } from '@/shared/api/httpClient';
import { CurrentUser, SignInRequest } from '@/shared/types/auth';

export async function signIn(request: SignInRequest): Promise<CurrentUser> {
  return apiRequest<CurrentUser>('/auth/signin/local', {
    method: 'POST',
    body: {
      email: request.email,
      password: request.password,
    },
  });
}

export async function getCurrentUser(): Promise<CurrentUser> {
  return apiRequest<CurrentUser>('/auth/me');
}

export async function refreshSession(): Promise<CurrentUser> {
  return apiRequest<CurrentUser>('/auth/refresh', {
    method: 'POST',
    skipAuthRefresh: true,
  });
}

export async function signOut(): Promise<void> {
  await apiRequest<void>('/auth/signout', {
    method: 'POST',
  });
}
