/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
global.manifestData=require("../resource/manifest.json");const testUtils=require("../resource/testUtils");const traverse=require("ast-traverse");var fs=require("fs");const path=require("path");for(let obj of global.manifestData){let componentMetadata=require("../metadata/"+obj.metadata+".json");if(componentMetadata.migrateTest){global.plugins=[global.plugins=["typescript","decorators"]];let webElementName=componentMetadata.migrateTest.type.to;let legacyTag=componentMetadata.legacyTag[3].toUpperCase()+componentMetadata.legacyTag.substring(4);let legacyName="";let upperCase=false;for(let char of legacyTag){if(char==="-"){upperCase=true}else{if(upperCase){legacyName+=char.toUpperCase();upperCase=false}else{legacyName+=char}}}let legacyTestAdapt;let filePath="../../../../../packages/oraclejet-webdriver/elements/"+componentMetadata.legacyTag+"/Oj"+legacyName+".ts";try{legacyTestAdapt=fs.readFileSync(path.resolve(__dirname,filePath),{encoding:"utf8"})}catch(err){continue}filePath="../../../../../packages/oraclejet-webdriver/elements/"+componentMetadata.legacyTag+"/Oj"+legacyName+"Base.ts";let legacyTestAdaptBase=fs.readFileSync(path.resolve(__dirname,filePath),{encoding:"utf8"});let legacyApi=[];let ast=testUtils.generateAST(legacyTestAdapt);traverse(ast,{pre:function(node){if(node.type==="ClassMethod"){legacyApi.push(node.key.name)}}});ast=testUtils.generateAST(legacyTestAdaptBase);traverse(ast,{pre:function(node){if(node.type==="ClassMethod"){legacyApi.push(node.key.name)}}});filePath="/Users/mmelendr/dev/jet/packages/oraclejet-core-pack/src/components/oj-c/"+componentMetadata.corePackTag.substring(5)+"/__webdriver__/"+webElementName+".ts";let corePackTestAdapt=fs.readFileSync(path.resolve(__dirname,filePath),{encoding:"utf8"});filePath="/Users/mmelendr/dev/jet/packages/oraclejet-core-pack/src/components/oj-c/"+componentMetadata.corePackTag.substring(5)+"/__webdriver__/"+webElementName+"Base.ts";let corePacktestAdaptBase=fs.readFileSync(path.resolve(__dirname,filePath),{encoding:"utf8"});let corePackApi=[];ast=testUtils.generateAST(corePackTestAdapt);traverse(ast,{pre:function(node){if(node.type==="ClassMethod"){corePackApi.push(node.key.name)}}});ast=testUtils.generateAST(corePacktestAdaptBase);traverse(ast,{pre:function(node){if(node.type==="ClassMethod"){corePackApi.push(node.key.name)}}});let delta=[];for(let method in legacyApi){if(!corePackApi.includes(legacyApi[method])){delta.push(legacyApi[method])}}filePath="/Users/mmelendr/dev/jet/rt/audit/jaf/corePackMigrator/metadata/"+legacyName[0].toLowerCase()+legacyName.substring(1)+"Metadata.json";if(delta.length>0){componentMetadata.migrateTest.ruleSetToIgnore=delta;fs.writeFileSync(path.resolve(__dirname,filePath),JSON.stringify(componentMetadata,null,1))}}}