import { cloneDeep } from 'lodash-es'
import { nanoid } from 'nanoid'
export const GEN_UUID = () => nanoid(8)
const defaultCpu = 1
const defaultMemory = 1
const defaultSysDisk = 50

export const subApplicationParam = {
  taskGroupUuid: GEN_UUID(),
  taskTargetUuid: GEN_UUID(),
  networkRelations: [],
  imageData: {},
  osList: [],
  versionList: [],
  subLocation: {
    region: '',
    az: '',
    vendorId: '',
    poolGroupId: '',
    vendorType: '',
    purpose: '',
    remark: '',
    resourceLabel: []
  },
  emption: {
    duration: {
      mode: 'Hour',
      amount: 1
    },
    count: 1
  },
  configs: {
    // 云主机信息相关
    name: '',
    nameRuleId: '',
    vmHostName: '',
    password: '',
    confirm_password: '',

    // 镜像相关
    osCategory: '',
    osVersion: '',
    imageId: '',
    templateDisk: '', // 前端用

    // 规格相关
    categoryId: '',
    cpu: defaultCpu,
    memory: defaultMemory,

    // 系统盘
    sysDisk: {
      categoryId: '',
      disk: defaultSysDisk
    },
    // 数据盘
    addDiskList: [],

    // 网卡相关
    networkCardConfigs: [
      {
        networkCardId: '',
        ipPolicy: 'Manual',
        ipPoolId: '',
        ipPoolName: '',
        portGroupId: '',
        address: [],
        mask: '',
        gateway: '',
        dns: ''
      }
    ]
  },
  elements: [
    {
      isLoadData: true,
      serviceCode: '',
      categoryId: '',
      category: '',
      specs: [
        {
          cpu: defaultCpu
        },
        {
          memory: defaultMemory
        }
      ],
      serviceItem: {}
    },
    {
      isLoadData: true,
      serviceCode: '',
      categoryId: '',
      category: '',
      specs: [
        {
          disk: defaultSysDisk
        }
      ],
      serviceItem: {}
    }
  ],
  service: ''
}
export const addNew = {
  workOrderTypeCode: 'CloudServerApplication', // 工单类型编号
  location: {
    name: '',
    businessId: '',
    businessName: '',
    projectId: '',
    projectName: '',
    creatorId: '',
    creatorName: '',
    menderId: '',
    menderName: '',
    ownerId: '',
    ownerName: '',
    tenantId: '',
    remark: ''
  },
  subApplicationParams: [cloneDeep(subApplicationParam)],
  tasks: []
}
export const defaultTask = {
  sceneId: '',
  templateId: '',
  taskGroupUuid: '',
  taskName: '',
  taskCode: 'standard'
}
export const ServiceCodeMap = {
  server: {
    VMWARE: 'vmware.standard.server',
    CNWARE: 'cnware.standard.server',
    ZSTACK: 'zstack.standard.server',
    CLOUDTOWER: 'cloudtower.standard.server',
    SANGFOR: 'sangfor.standard.server',
    CECSTACK: 'cecstack.standard.server',
    INSPURRAIL: 'inspurrail.standard.server'
  },
  disk: {
    VMWARE: 'vmware.storage.disk',
    CNWARE: 'cnware.standard.volume',
    ZSTACK: 'zstack.storage.disk',
    CLOUDTOWER: 'cloudtower.standard.volume',
    SANGFOR: 'sangfor.storage.disk',
    CECSTACK: 'cecstack.standard.volume',
    INSPURRAIL: 'inspurrail.standard.volume'
  }
}
