import { NameMapper } from "../../zero-types/src/name-mapper.js";
function clientToServer(tables) {
  return createMapperFrom("client", tables);
}
function serverToClient(tables) {
  return createMapperFrom("server", tables);
}
function createMapperFrom(src, tables) {
  const mapping = new Map(
    Object.entries(tables).map(
      ([tableName, { serverName: serverTableName, columns }]) => {
        let allColumnsSame = true;
        const names = {};
        for (const [name, { serverName }] of Object.entries(columns)) {
          if (serverName && serverName !== name) {
            allColumnsSame = false;
          }
          if (src === "client") {
            names[name] = serverName ?? name;
          } else {
            names[serverName ?? name] = name;
          }
        }
        return [
          src === "client" ? tableName : serverTableName ?? tableName,
          {
            tableName: src === "client" ? serverTableName ?? tableName : tableName,
            columns: names,
            allColumnsSame
          }
        ];
      }
    )
  );
  return new NameMapper(mapping);
}
function validator(tablesToColumns) {
  const identity = new Map(
    [...tablesToColumns.entries()].map(([tableName, columns]) => [
      tableName,
      {
        tableName,
        columns: Object.fromEntries(columns.map((c) => [c, c])),
        allColumnsSame: true
      }
    ])
  );
  return new NameMapper(identity);
}
export {
  NameMapper,
  clientToServer,
  serverToClient,
  validator
};
//# sourceMappingURL=name-mapper.js.map
