import { AuthLoginResponse, UserResponse } from "@/api/types";
import { AxiosError } from "axios";
import { createContext } from "react";

export interface LoginOptions {
  onSuccess?: (data: AuthLoginResponse) => void;
  onError?: (error: AxiosError) => void
}

interface AuthContextType {
  user?: UserResponse;
  isAuthorized: boolean;
  isLoading: boolean;
  login: (email: string, password: string, options?: LoginOptions) => void;
  logout: () => void;
  errorLogin?: Error|null;
  isPendingLogin: boolean;
}

const AuthContext = createContext<AuthContextType>({
  user: undefined,
  isAuthorized: false,
  isLoading: false,
  login: (email, password) => {},
  logout: () => {},
  errorLogin: null,
  isPendingLogin: false
});

export default AuthContext;