import { BusController } from "@/controllers/natsController";
import { TreeController } from "@/controllers/queentreeController";
import { Dict_Apis } from "@/dict";
import { PageListController, UploadController } from "@queenjs/controllers";
import { ModuleRoot } from "queenjs";
import { actions } from "./actions";
import { compoents } from "./components";
import { helper } from "./helper";
import { http } from "./http";
import { store } from "./store";

export class ResourceModule extends ModuleRoot {
  config = this.setConfig({
    httpConfig: {
      baseURL: Dict_Apis.promotion,
    },
  });

  actions = this.createActions(actions);
  components = this.useComponents(compoents);
  store = this.createStore([store]);
  https = this.createHttps(http);
  helper = this.createHelper(helper);

  controls = {
    uploader: new UploadController({
      httpConfig: {
        baseURL: Dict_Apis.queentree,
      },
      dir: "queenshow",
    }),
    promotionListCtrl: new PageListController(this.config?.httpConfig),
    materialListCtrl: new PageListController(this.config?.httpConfig),
    matTempListCtrl: new PageListController(this.config?.httpConfig),
    renderTaskListCtrl: new PageListController(this.config?.httpConfig),

    materialImageListCtrl: new PageListController(this.config?.httpConfig),
    materialVideoListCtrl: new PageListController(this.config?.httpConfig),
  };
  natsBus = new BusController();
  treeController = new TreeController(this.natsBus);

  onReady() {
    this.controls.promotionListCtrl.setCrudPrefix("/h5");
    this.controls.promotionListCtrl.state.size = 12;
    this.controls.materialListCtrl.setCrudPrefix("/source");
    this.controls.materialListCtrl.state.size = 24;
    this.controls.renderTaskListCtrl.setCrudPrefix("/sourceGen");
    this.controls.renderTaskListCtrl.state.size = 24;
    this.controls.matTempListCtrl.setCrudPrefix("/tpls");
    this.controls.matTempListCtrl.state.size = 20;

    this.controls.materialImageListCtrl.setCrudPrefix("/source")
    this.controls.materialImageListCtrl.state.size = 18;
    this.controls.materialImageListCtrl.state.query = {fileType:"image"}

    this.controls.materialVideoListCtrl.setCrudPrefix("/source")
    this.controls.materialVideoListCtrl.state.size = 18;
    this.controls.materialVideoListCtrl.state.query = {fileType:"video"}

    this.natsBus.init()
  }
}

export const { useResource, initResource } = ResourceModule.hook("Resource");
