import { entityKind } from "../../entity.js";
import { getColumnNameAndConfig } from "../../utils.js";
import { CockroachColumn, CockroachColumnWithArrayBuilder } from "./common.js";
import { parseEWKB } from "./utils.js";
class CockroachGeometryBuilder extends CockroachColumnWithArrayBuilder {
  static [entityKind] = "CockroachGeometryBuilder";
  constructor(name) {
    super(name, "array", "CockroachGeometry");
  }
  /** @internal */
  build(table) {
    return new CockroachGeometry(
      table,
      this.config
    );
  }
}
class CockroachGeometry extends CockroachColumn {
  static [entityKind] = "CockroachGeometry";
  getSQLType() {
    return "geometry(point)";
  }
  mapFromDriverValue(value) {
    return parseEWKB(value);
  }
  mapToDriverValue(value) {
    return `point(${value[0]} ${value[1]})`;
  }
}
class CockroachGeometryObjectBuilder extends CockroachColumnWithArrayBuilder {
  static [entityKind] = "CockroachGeometryObjectBuilder";
  constructor(name) {
    super(name, "json", "CockroachGeometryObject");
  }
  /** @internal */
  build(table) {
    return new CockroachGeometryObject(
      table,
      this.config
    );
  }
}
class CockroachGeometryObject extends CockroachColumn {
  static [entityKind] = "CockroachGeometryObject";
  getSQLType() {
    return "geometry(point)";
  }
  mapFromDriverValue(value) {
    const parsed = parseEWKB(value);
    return { x: parsed[0], y: parsed[1] };
  }
  mapToDriverValue(value) {
    return `point(${value.x} ${value.y})`;
  }
}
function geometry(a, b) {
  const { name, config } = getColumnNameAndConfig(a, b);
  if (!config?.mode || config.mode === "tuple") {
    return new CockroachGeometryBuilder(name);
  }
  return new CockroachGeometryObjectBuilder(name);
}
export {
  CockroachGeometry,
  CockroachGeometryBuilder,
  CockroachGeometryObject,
  CockroachGeometryObjectBuilder,
  geometry
};
//# sourceMappingURL=geometry.js.map