import {NotNull, TextFormatter, Visible} from "@webbpm/base-package";

export class PrefixSuffixTextFormatter implements TextFormatter {

  @NotNull()
  public hasPrefix: boolean;

  @Visible("hasPrefix == true")
  @NotNull("hasPrefix == true")
  public prefix: string;

  @NotNull()
  public hasSuffix: boolean;

  @Visible("hasSuffix == true")
  @NotNull("hasSuffix == true")
  public suffix: string;

  format(value: string): string {
    if (value) {
      let prefix = this.hasPrefix ? this.prefix + " " : "";
      let suffix = this.hasSuffix ? " " + this.suffix : "";
      return prefix + value + suffix;
    }

    return value;
  }
}
