import type { AuthApi } from '#/api/cdcm';

import { defineStore } from 'pinia';

export const useTokenStore = defineStore('token', {
  state: () => ({
    token: null as null | string,
  }),
  actions: {
    setToken(token: string) {
      this.token = token;
    },
    deleteToken() {
      this.token = null;
    },
  },
});

export const useStaticConfigStore = defineStore('static_config', {
  state: () => ({
    support_template_types: [] as string[],
    support_driver_types: [] as string[],
    support_point_types: [] as string[],
    support_point_access_types: [] as string[],
  }),
  actions: {
    setConfig(data: AuthApi.LoginResult) {
      this.support_template_types = data.data.support_template_types ?? [];
      this.support_driver_types = data.data.support_driver_types ?? [];
      this.support_point_types = data.data.support_point_types ?? [];
      this.support_point_access_types =
        data.data.support_point_access_types ?? [];
    },
  },
});

export const deviceTemplate = defineStore('support_device_template', {
  state: () => ({
    support_device_template: [] as string[],
  }),
  actions: {
    setData(data: any) {
      this.support_device_template = data;
    },
  },
});
