import type { SessionData } from '@/types/Auth'
import { create } from 'zustand'

type SessionState = {
  session: SessionData
  setSession: (session: SessionData) => void
  reset: () => void
}

type InitialState = {
  session: SessionData
}

const initialState: InitialState = {
  session: {
    langCd: null,
    currPage: 0,
    rowCount: 0,
    startRow: null,
    endRow: null,
    compCd: null,
    agencyStoreId: null,
    storeId: null,
    storeNm: null,
    userId: null,
    category: null,
    userNm: null,
    userNmKana: null,
    telNo: null,
    fax: null,
    email: null,
    lastEditUser: null,
    storeGubun: null,
    pwCurr: null,
    pwdInitYn: null,
    apprStatCd: null,
    loginFailCnt: 0,
    loginFailMinYn: null,
    priceViewStatCd: null,
    groupId: null,
    storeLvl: null,
    custCd: null,
    builderNo: null,
    isLoggedIn: false,
    role: null,
  },
}

export const useSessionStore = create<SessionState>((set) => ({
  ...initialState,
  setSession: (value: SessionData) => set((state) => ({ ...state, session: { ...state.session, ...value } })),
  reset: () => set(initialState),
}))
