import { mutateData } from "../../../lib/utils/index.js";
import { formatDocAsApiDescription, formatDocAsJavaDoc } from "../../java/support/doc.js";
import { getJoinTableName } from "./database.js";
import { hibernateSnakeCase } from "./string.js";
export function prepareRelationshipForDatabase({ application, entity, relationship, }) {
    // Database properties are used by liquibase and spring-boot there is no inheritance between them.
    mutateData(relationship, {
        // DB properties
        columnName: ({ relationshipName }) => hibernateSnakeCase(relationshipName),
        shouldWriteJoinTable: ({ ownerSide, relationshipManyToMany }) => application.databaseTypeSql && relationshipManyToMany && ownerSide,
        joinTable: ({ shouldWriteJoinTable, relationshipName }) => shouldWriteJoinTable ?
            {
                name: getJoinTableName(entity.entityTableName, relationshipName, {
                    prodDatabaseType: application.prodDatabaseType,
                }).value,
            }
            : undefined,
    });
}
export function prepareRelationship({ application, entity, relationship, }) {
    if (relationship.documentation) {
        mutateData(relationship, {
            __override__: false,
            relationshipJavadoc: formatDocAsJavaDoc(relationship.documentation, 4),
            relationshipApiDescription: formatDocAsApiDescription(relationship.documentation),
            propertyApiDescription: ({ relationshipApiDescription }) => relationshipApiDescription,
        });
    }
    prepareRelationshipForDatabase({ application, entity, relationship });
}
