import { create } from "zustand";

import type { TSystemCoreCnf } from '@/types/system'

import {
  getSysCoreCnf,
  
} from "@/service/system";
import Taro from "@tarojs/taro";
import { OSS_PUBLIC_BUCKET_NAME_KEY } from "@/xiaolanbenlib/constant";


export interface SystemStoreState {
  sysCoreCnf: TSystemCoreCnf | null;
  fetchSysCoreCnf: () => Promise<TSystemCoreCnf|null>;
}

export const useSystemStore = create<SystemStoreState>((set, get) => ({
  sysCoreCnf: null,
  fetchSysCoreCnf: async () => {
    const response = await getSysCoreCnf()
    if (response && response?.data) {
      Taro.setStorageSync(OSS_PUBLIC_BUCKET_NAME_KEY, response.data?.ossPublicBucketName)
      set({ sysCoreCnf: response.data });
      return response.data;
    }

    return null;
  }
}));
