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

const LOCAL_NAME = 'settingsStorage'
let defalutSystem = ''

export interface SettingsState {
    systemMessage: string
    temperature: number
    top_p: number
}

export function defaultSetting(): SettingsState {
    return {
        systemMessage: defalutSystem,
        temperature: 0.8,
        top_p: 1
    }
}

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

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

export function removeLocalState() {
    ss.remove(LOCAL_NAME)
}

export function getSystem() {
    fetchSystemMessage().then((res: any) => {
        defalutSystem = res.value
    })
}
