import { aigcTypeExists } from '../basic-types/aigc-types.js';
export default class JDLAigc {
    from;
    to;
    type;
    injectedFieldInFrom;
    commentInFrom;
    constructor(args) {
        const merged = mergeDefaultsWithOverrides(args);
        if (!merged.from) {
            throw new Error('Source and destination entities must be passed to create a relationship.');
        }
        if (!aigcTypeExists(merged.type)) {
            throw new Error('A valid type and at least one injected field must be passed to create a relationship.');
        }
        this.from = merged.from;
        this.to = merged.to;
        this.type = merged.type;
        this.injectedFieldInFrom = merged.injectedFieldInFrom;
        this.commentInFrom = merged.commentInFrom;
    }
    getId() {
        return `${this.type}_${this.from}${this.injectedFieldInFrom ? `{${this.injectedFieldInFrom}}` : ''}_${this.to}`;
    }
    toString() {
        let string = `aigc ${this.type} {\n  `;
        if (this.commentInFrom) {
            string += `/**\n${this.commentInFrom
                .split('\n')
                .map(line => `   * ${line}\n`)
                .join('')}   */\n  `;
        }
        string += `${this.from}`;
        if (this.injectedFieldInFrom) {
            string += `{${this.injectedFieldInFrom}}`;
        }
        string += ' to';
        string += ' ';
        string += `${this.to}`;
        string += '\n}';
        return string.replace(/ \n/g, '\n').replace(/[ ]{4}/g, '  ');
    }
}
function mergeDefaultsWithOverrides(overrides) {
    const defaultOptions = defaults();
    return {
        ...defaultOptions,
        ...overrides,
    };
}
function defaults() {
    return {
        injectedFieldInFrom: null,
        commentInFrom: '',
    };
}
