import { D as T, M as h, S as f, p as _, a as H, w as b, n as A, j as R, b as n, c as u, d as w } from "./apply-styled-options-to-query-BagjzMqm.js";
class y extends T {
  constructor(t, e, r, o, d, m, l, c, a, g) {
    if (super(t, d || h.Dimension, m, c, a), this.__serializable = "DimensionalDimension", this._dimensions = [], this._attributes = [], this._sort = f.None, !a && e) {
      const { table: D, column: s } = _(e);
      this.composeCode = `${H}.${b(D)}.${b(s)}`;
    }
    this._sort = l || f.None, this._expression = e, this.setDimensions(o || []), this.setAttributes(r), g && (this.defaultAttribute = g);
  }
  static parseType(t) {
    switch (t) {
      case "datetime":
      case h.DateDimension:
        return h.DateDimension;
      case "text":
      case h.TextDimension:
        return h.TextDimension;
      case "numeric":
      case h.NumericDimension:
        return h.NumericDimension;
    }
    return h.TextDimension;
  }
  getAttachedName(t, e) {
    let r = t;
    const o = A(t);
    return (o === "id" || o === "name" || Object.getOwnPropertyDescriptor(this, o) !== void 0 || this[o] !== void 0) && (r = e), r;
  }
  setDimensions(t) {
    this._dimensions = t;
    for (let e = 0; e < t.length; e++) {
      const r = this.getAttachedName(t[e].name, t[e].attributes[0].expression);
      this[A(r)] = t[e], r != t[e].name && (t[e].name = r);
    }
  }
  setAttributes(t) {
    this._attributes = t || [];
    for (let e = 0; e < t.length; e++) {
      const r = this.getAttachedName(t[e].name, t[e].expression);
      this[A(r)] = t[e], t[e].name != r && (t[e].name = r);
    }
  }
  /**
   * gets the element's ID
   */
  get id() {
    return this._expression;
  }
  /**
   * Gets the child attributes
   */
  get attributes() {
    return this._attributes;
  }
  /**
   * Gets the child dimensions
   */
  get dimensions() {
    return this._dimensions;
  }
  get expression() {
    return this._expression;
  }
  /**
   * Gets the sort definition of this instance
   *
   * @returns The Sort definition of this instance
   */
  getSort() {
    return this._sort;
  }
  /**
   * Gets a sorted {@link Dimension} with the given definition
   *
   * @param sort - Sort definition
   * @returns An instance representing the sorted {@link Dimension} of this instance
   */
  sort(t) {
    return new y(this.name, this.expression, this.attributes, this.dimensions, this.type, this.description, t, this.dataSource, this.composeCode, this.defaultAttribute);
  }
  /**
   * Gets a serializable representation of the element
   */
  serialize() {
    const t = super.serialize();
    return t.expression = this.expression, this.getSort() !== void 0 && (t.sort = this.getSort()), t.attributes = this._attributes.map((e) => e.serialize()), t.dimensions = this._dimensions.map((e) => e.serialize()), this.defaultAttribute && (t.defaultAttribute = this.defaultAttribute.serialize()), t;
  }
  /**
   * Gets the JAQL representation of this instance
   *
   * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
   */
  jaql(t) {
    if (this.defaultAttribute)
      return this.defaultAttribute.jaql(t);
    if (this.dimensions.length > 0)
      return this.dimensions[0].jaql(t);
    const e = {
      jaql: {
        title: this.name,
        dim: this.expression,
        datatype: R(this.type)
      }
    };
    return this._sort != f.None && (e.jaql.sort = this._sort == f.Ascending ? "asc" : "desc"), t === !0 ? e.jaql : e;
  }
}
const z = (i) => i && i.__serializable === "DimensionalDimension";
class p extends y {
  constructor(t, e, r, o, d, m, l, c) {
    super(t, e, [], [], h.DateDimension, r, o, d, m), this.__serializable = "DimensionalDateDimension";
    const a = [r, o, d, void 0, void 0, l, c];
    this.defaultLevel = n.Years, this.Years = new u(n.Years, e, n.Years, "yyyy", ...a), this.Quarters = new u(n.Quarters, e, n.Quarters, "Q yyyy", ...a), this.Months = new u(n.Months, e, n.Months, "yyyy-MM", ...a), this.Weeks = new u(n.Weeks, e, n.Weeks, "ww yyyy", ...a), this.Days = new u(n.Days, e, n.Days, "yyyy-MM-dd", ...a), this.Hours = new u(n.Hours, e, n.Hours, "yyyy-MM-dd HH:mm", ...a), this.MinutesRoundTo30 = new u(n.MinutesRoundTo30, e, n.MinutesRoundTo30, "yyyy-MM-dd HH:mm", r, o, d), this.MinutesRoundTo15 = new u(n.MinutesRoundTo15, e, n.MinutesRoundTo15, "yyyy-MM-dd HH:mm", ...a), this.Minutes = new u(n.Minutes, e, n.Minutes, "yyyy-MM-dd HH:mm", ...a), this.Seconds = new u(n.Seconds, e, n.Seconds, "yyyy-MM-dd HH:mm:ss", r, o, d), this.AggHours = new u(n.AggHours, e, n.AggHours, "HH:mm", ...a), this.AggMinutesRoundTo30 = new u(n.AggMinutesRoundTo30, e, n.AggMinutesRoundTo30, "HH:mm", r, o, d), this.AggMinutesRoundTo15 = new u(n.AggMinutesRoundTo15, e, n.AggMinutesRoundTo15, "HH:mm", ...a), this.AggMinutesRoundTo1 = new u(n.AggMinutesRoundTo1, e, n.AggMinutesRoundTo1, "HH:mm", ...a), this.setAttributes([
      this.Years,
      this.Quarters,
      this.Months,
      this.Weeks,
      this.Days,
      this.Hours,
      this.MinutesRoundTo30,
      this.MinutesRoundTo15,
      this.Minutes,
      this.Seconds,
      this.AggHours,
      this.AggMinutesRoundTo30,
      this.AggMinutesRoundTo15,
      this.AggMinutesRoundTo1
    ]);
  }
  /**
   * gets the element's ID
   */
  get id() {
    return this.expression;
  }
  setDimensions() {
  }
  setAttributes(t) {
    this._attributes = t;
  }
  /**
   * Gets the sort definition of this instance
   *
   * @returns The Sort definition of this instance
   */
  getSort() {
    return this._sort;
  }
  /**
   * Gets a sorted {@link Dimension} with the given definition
   *
   * @param sort - Sort definition
   * @returns An instance representing the sorted {@link Dimension} of this instance
   */
  sort(t) {
    return new p(this.name, this.expression, this.description, t, this.dataSource, this.composeCode, this.indexed, this.merged);
  }
  /**
   * Gets a serializable representation of the element
   */
  serialize() {
    return super.serialize();
  }
  /**
   * Gets the JAQL representation of this instance
   *
   * @param nested - defines whether the JAQL is nested within parent JAQL statement or a root JAQL element
   */
  jaql(t) {
    const e = this[this.defaultLevel].jaql();
    return e.jaql.title = this.name, t ? e.jaql : e;
  }
}
const S = (i) => i && i.__serializable === "DimensionalDateDimension";
function N(i) {
  const t = i.name || i.title, e = i.desc || i.description, r = i.expression || i.dim, o = y.parseType(i.dimtype || i.type), d = i.sort, m = i.dataSource, l = i.indexed, c = i.merged;
  if (o == h.DateDimension)
    return new p(t, r, e, d, m, void 0, l, c);
  const a = Object.getOwnPropertyNames(i).map((s) => i[s]).filter((s) => h.isAttribute(s == null ? void 0 : s.type));
  if (a.length == 0)
    if (i.attributes) {
      let s;
      for (let M = 0; M < i.attributes.length; M++)
        s = i.attributes[M], a.push(new w(s.name, s.expression, s.type, s.description, s.sort, s.dataSource, void 0, void 0, s.indexed, s.merged));
    } else r && a.push(new w(t, r, o, e, d, m, void 0, void 0, l, c));
  const g = Object.getOwnPropertyNames(i).map((s) => i[s]).filter((s) => h.isDimension(s == null ? void 0 : s.type));
  if (g.length == 0 && i.dimensions)
    for (let s = 0; s < i.dimensions.length; s++)
      g.push(N(i.dimensions[s]));
  const D = new y(t, r, a, g, o, e, d, m);
  return i.defaultAttribute && (D.defaultAttribute = a.find((s) => s.name === i.defaultAttribute)), D;
}
function q(i) {
  const t = i.name || i.title, e = i.expression || i.dim, r = i.desc || i.description, o = i.sort, d = i.dataSource;
  return new p(t, e, r, o, d, void 0, i.indexed, i.merged);
}
export {
  y as D,
  q as a,
  S as b,
  N as c,
  p as d,
  z as i
};
