import { ss } from '@/utils/storage'

const LOCAL_NAME = 'userMemberStorage'

export interface MemberShip {
    createdAt: Date
    duration: number
    id: number
    name: String
    price: number
    enabled?: boolean
}

export interface UserMember {
    userId?: number | null
    planId?: number | null
    expireAt: any
    createdAt: any
    memberType: string | null
}

export interface UserMemberState {
    userMember: UserMember
}

export function defaultSetting(): UserMemberState {
    return {
        userMember: {
            expireAt: '2023-04-19T09:04:21.332Z',
            createdAt: '2023-04-19T09:04:21.332Z',
            memberType: 'TRIAL'
        }
    }
}

export function getLocalState(): UserMemberState {
    const localSetting: UserMemberState | undefined = ss.get(LOCAL_NAME)
    return { ...defaultSetting(), ...localSetting }
}

export function setLocalState(setting: UserMemberState): void {
    ss.set(LOCAL_NAME, setting)
}
