import listOSS from './list'
import upload, { UploadOssOptions } from './upload'


interface GenerateHandler {
  ls: () => void
  list: () => void
  upload: () => void
}

type Types = keyof GenerateHandler

async function publish(type: Types, options: UploadOssOptions) {
  const paramsHandler: GenerateHandler = {
    ls: listOSS, // 展示oss列表(简写)
    list: listOSS, // 展示oss列表
    upload: () => {
      upload(options)
    }, // 上传oss
  }
  if (Object.prototype.hasOwnProperty.call(paramsHandler, type)) {
    const fn = paramsHandler[type]
    await fn()
  }
}

// 发布命令的核心逻辑
async function execOss(options: UploadOssOptions) {
  Object.keys(options).forEach(async (type) => {
    await publish(type as Types, options)
  })
}

export default execOss
