import { Subject } from "rxjs";
import { Http } from "../Http";
import { ExportAsync } from "./ExportAsync";
import { Image } from "../models/Image";
import { Geometry } from "../models/Geometry";
import { AstHelper } from "@gvol-org/geovis-brain-core";
import { ImageCollection } from "../models/ImageCollection";
import { Palette } from "../models/Palette";
/**
 * @class Export.gif
 * @since Export
 * @todo gif.toDrive
 */
export class gif extends ExportAsync {
  /**
   * @hideconstructor
   * @see Export.gif
   * @returns Export.gif
   */
  constructor(...param: any[]) {
    super();
    if (!(this instanceof gif)) {
      return new gif(param);
    }
  }

  /**
   * 导出影像数据
   * @param {Object} args 导出对象
   * @tutorial Export.gif
   */
  static toDrive(args: {
    imageCollection: ImageCollection | any;
    description?: string;
    width?: number;
    height?: number;
    title?: string;
    assetId?: string;
    palette?: Palette
  }) {

    let newObj = JSON.parse(JSON.stringify(args));
    let { newChain, newOrder } = AstHelper.objectParamChain(newObj);

    newChain.push({
      "functionName": "Export.gif.toDrive",
      "arguments": {
        "args": newObj
      },
      "order": newOrder
    })
    let content = {
      type: 'map',
      chain: newChain
    };
    if ((window as any).astCallback) {
      (window as any).astCallback(content);
      return;
    }
    let exportObj = new ExportAsync();
    exportObj.execute(async () => {
      let data = await Http.getRequest(newChain, false, true);
      Http.responseSubject$.next(data);
      if (data && data.data.status == "success") {
        exportObj.param = data;
        // console.log("subjecttttt", this.exportSubject$);
        this.exportSubject$.next(data.data.detail);
      } else {
        // console.log("应当删除export")
      }
    });
    return exportObj;
  }

}