/**
 * 工作区模块
 */
import { Module, VuexModule, getModule } from 'vuex-module-decorators';
import store from '@/store';
import { session } from '@/store/modules/session';

export interface Area {
  driveClassName: string | null;
  parkName: string;
  poolName: string;
  // warehouseType: '1' | '2';
  url: string;
  userName: string;
  // workareaCode: string;
  // workareaName: string;
}
export interface Factory {
  factory: string;
  factoryname: string;
  value: string;
  label: string;
  poolName: string;
}

@Module({ dynamic: true, store, namespaced: true, name: 'area' })
class AreaService extends VuexModule {
  // 工作区列表
  get areas(): Array<Factory> {
    if (session.user && session.getUser.poolNameList) {
      return session.getUser.poolNameList.map((area) => ({
        factory: area.poolName.split('_')[1],
        factoryname: area.parkName,
        value: area.poolName.split('_')[1],
        label: area.parkName,
        poolName: area.poolName,
      }));
    } else {
      return [];
    }
  }
}

export const area = getModule(AreaService);
