import type {
	IS_LOGGING_IN,
	LOGOUT,
	RESET_LOADING,
	SET_ERROR,
	SET_GLOBAL_LANGUAGES,
	SET_GLOBAL_SETTINGS,
	SET_HAS_ANIMATION,
	SET_IS_LOADING,
	SET_IS_SAVING,
	SET_LANGUAGE,
	SET_SESSION_STARTED_AT,
	SET_TOKEN,
	SET_USER,
} from "./constants";
import type { IUser } from "./reducer";

export interface ISetTokenAction {
	type: typeof SET_TOKEN;
	payload: { token: string };
}

export interface ILogoutAction {
	type: typeof LOGOUT;
	payload: { token: string };
}

export interface IIsLoggingInAction {
	type: typeof IS_LOGGING_IN;
	payload: { isLoggingIn: boolean };
}
export interface ISetErrorAction {
	type: typeof SET_ERROR;
	payload: {
		code?: any;
		text: any;
	};
}

export interface ISetIsLoading {
	type: typeof SET_IS_LOADING;
	payload: { isLoading: boolean };
}

export interface ISetIsSaving {
	type: typeof SET_IS_SAVING;
	payload: { isSaving: boolean };
}

export interface ISetLanguageAction {
	type: typeof SET_LANGUAGE;
	payload: { lang: { locale: string; id: number | null } };
}

export interface ISetGlobalLanguages {
	type: typeof SET_GLOBAL_LANGUAGES;
	payload: { globalLangs: any[] };
}

export interface ISetGlobalSettings {
	type: typeof SET_GLOBAL_SETTINGS;
	payload: { globalSettings: any[] };
}

export interface ISetUserAction {
	type: typeof SET_USER;
	payload: { user: IUser };
}

export interface ISetSessionStartedAtAction {
	type: typeof SET_SESSION_STARTED_AT;
	payload: { sessionStartedAt: null | Date };
}

export interface ISetHasAnimation {
	type: typeof SET_HAS_ANIMATION;
	payload: { hasAnimation: boolean };
}

export interface IResetLoading {
	type: typeof RESET_LOADING;
}

export type AppActionsCreators = ISetIsLoading & ISetIsSaving;

export type AuthActionsCreators = ISetTokenAction &
	ILogoutAction &
	ISetErrorAction &
	IIsLoggingInAction &
	ISetUserAction &
	ISetSessionStartedAtAction;
