import { create } from "zustand";
import { persist } from "zustand/middleware";

import { User } from "@/entities";

interface State {
	user?: User;

	login: (user: User) => void;
	logout: () => void;
}

export const useIdentityStore = create<State>()(
	persist(
		(set) => ({
			user: undefined,

			login: (user: User) => {
				set({
					user,
				});
			},

			logout: () => {
				set({
					user: undefined,
				});
			},
		}),
		{
			name: "identity",
			version: 1,
		}
	)
);
