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

export interface Area {
  loginName: string | null;
  warehouseCode: string;
  warehouseName: string;
  warehouseType: '1' | '2';
  regionCode: string;
  regionDesc: string;
  workareaCode: string;
  workareaName: string;
}

@Module({ dynamic: true, store, namespaced: true, name: 'area' })
class AreaService extends VuexModule {
  // 工作区列表
  get areas(): Array<Area> {
    if (session.user && session.getUser.list) {
      return session.getUser.list.map((area) => ({
        ...area,
        formattedWarehouseType:
          area.warehouseType === '1' ? 'RAW' : area.warehouseType === '2' ? 'FG' : 'SFG',
      }));
    } else {
      return [];
    }
  }
}

export const area = getModule(AreaService);
