import GlobalData from "src/common/GlobalData";

export default class FileSuffixHelper {
  public static kVideoDefaultSuffix = ".mp4;.avi;.ts;.webm;.flv;.mkv;.wmv;";
  public static kImageDefaultSuffix = ".jpg;.png;.bmp;";
  public static debug_mode = false;

  public static get videoSuffix() {
    if (FileSuffixHelper.debug_mode) {
      return "";
    }
    return (
      GlobalData.getInstance().applicationConfig?.video_suffix_filter ||
      FileSuffixHelper.kVideoDefaultSuffix
    );
  }

  public static isVideoPath(path: string): boolean {
    return this.isPathToSuffix(
      path,
      this.videoSuffix || FileSuffixHelper.kVideoDefaultSuffix
    );
  }

  public static get imageSuffix() {
    if (FileSuffixHelper.debug_mode) {
      return "";
    }
    return (
      GlobalData.getInstance().applicationConfig?.image_suffix_filter ||
      FileSuffixHelper.kImageDefaultSuffix
    );
  }

  public static isImagePath(path: string): boolean {
    return this.isPathToSuffix(
      path,
      this.imageSuffix || FileSuffixHelper.kImageDefaultSuffix
    );
  }

  public static isPathToSuffix(path: string, suffixFilter: string): boolean {
    if (path && suffixFilter) {
      for (const suffix of suffixFilter
        .split(";")
        .filter((e) => e && e != "")) {
        if (path.endsWith(suffix)) {
          return true;
        }
      }
    }
    return false;
  }

  public static get allSuffix() {
    if (FileSuffixHelper.debug_mode) {
      return null;
    }

    return (
      (this.videoSuffix || FileSuffixHelper.kVideoDefaultSuffix) +
      (this.imageSuffix || FileSuffixHelper.kImageDefaultSuffix)
    );
  }
}
