import { visit } from '@takeshape/util';
import get from 'lodash/get.js';
import omit from 'lodash/omit.js';
import set from 'lodash/set.js';
const migrate = async (_, projectSchema) => {
    visit(projectSchema, ['@user'], (_, path) => {
        const parentPath = path.slice(0, -1);
        const oldSchema = get(projectSchema, parentPath);
        const newSchema = {
            ...omit(oldSchema, ['@user', 'type']),
            '@ref': 'local:TSUser',
            '@input': { type: 'string' },
            '@resolver': { name: 'takeshape:getUser', service: 'takeshape:local' }
        };
        set(projectSchema, parentPath, newSchema);
    });
    return {
        ...projectSchema,
        schemaVersion: '3.17.0'
    };
};
export default migrate;
