'use strict';function _0x4630(){const _0x163404=['\x20tables\x20to\x20process','getTableSchema','initailizeAiConfig','object','embeddings','table_name','exports','embedding','decryptData','configurations','./prisma.service','openai','openai_api_key','\x20(required)','enumerable','Table:\x20','\x20embedded\x20and\x20stored','1135768PlPDGc','join','default','text-embedding-3-small','data','Project\x20Sync\x20-\x20Failed:','4210EdTrHT','2005600qadSQW','data_type','embeddingVectorLogs','embedAndStore','getPrototypeOf','3719933tqrLwf','Project\x20Sync\x20-\x20Completed\x20successfully','encryptionService','Processing\x20table:\x20','801SWSQzJ','\x20chunk\x20created','total_tokens','findFirst','chunk','toFixed','error','usage','map','1XJrAKn','6842676rsglxl','22636TjukDW','16ehFwrk','length','Project\x20Sync\x20-\x20Starting','is_nullable','132kRLYlo','getTables','18054sBhEgc','Error\x20processing\x20table\x20','schemaChunk','generateSchemaChunks','getOwnPropertyDescriptor','function','./encryption.service','\x0aColumns:\x0a','call','log','__esModule','hasOwnProperty','generateVectorForTable','$executeRaw','create','3553548Biwbxx','$queryRaw'];_0x4630=function(){return _0x163404;};return _0x4630();}const _0x77c0db=_0x3982;(function(_0x1a576a,_0x7ceced){const _0x31d4f1=_0x3982,_0x15f80f=_0x1a576a();while(!![]){try{const _0x302ebd=parseInt(_0x31d4f1(0xe7))/0x1*(-parseInt(_0x31d4f1(0xce))/0x2)+-parseInt(_0x31d4f1(0xde))/0x3*(-parseInt(_0x31d4f1(0xe9))/0x4)+parseInt(_0x31d4f1(0xd5))/0x5+parseInt(_0x31d4f1(0xe8))/0x6+parseInt(_0x31d4f1(0xda))/0x7*(parseInt(_0x31d4f1(0xea))/0x8)+-parseInt(_0x31d4f1(0xf0))/0x9*(-parseInt(_0x31d4f1(0xd4))/0xa)+parseInt(_0x31d4f1(0xee))/0xb*(-parseInt(_0x31d4f1(0xff))/0xc);if(_0x302ebd===_0x7ceced)break;else _0x15f80f['push'](_0x15f80f['shift']());}catch(_0x1a7526){_0x15f80f['push'](_0x15f80f['shift']());}}}(_0x4630,0xccb33));function _0x3982(_0x587c53,_0x4caaaa){_0x587c53=_0x587c53-0xc7;const _0x463044=_0x4630();let _0x398297=_0x463044[_0x587c53];return _0x398297;}var __create=Object[_0x77c0db(0xfe)],__defProp=Object['defineProperty'],__getOwnPropDesc=Object[_0x77c0db(0xf4)],__getOwnPropNames=Object['getOwnPropertyNames'],__getProtoOf=Object[_0x77c0db(0xd9)],__hasOwnProp=Object['prototype'][_0x77c0db(0xfb)],__export=(_0x25d301,_0x465166)=>{for(var _0x374c45 in _0x465166)__defProp(_0x25d301,_0x374c45,{'get':_0x465166[_0x374c45],'enumerable':!![]});},__copyProps=(_0x9ea481,_0x3c3a23,_0xc69fb3,_0x1464c1)=>{const _0x34d38c=_0x77c0db;if(_0x3c3a23&&typeof _0x3c3a23===_0x34d38c(0x104)||typeof _0x3c3a23===_0x34d38c(0xf5)){for(let _0x219d4a of __getOwnPropNames(_0x3c3a23))if(!__hasOwnProp[_0x34d38c(0xf8)](_0x9ea481,_0x219d4a)&&_0x219d4a!==_0xc69fb3)__defProp(_0x9ea481,_0x219d4a,{'get':()=>_0x3c3a23[_0x219d4a],'enumerable':!(_0x1464c1=__getOwnPropDesc(_0x3c3a23,_0x219d4a))||_0x1464c1[_0x34d38c(0xcb)]});}return _0x9ea481;},__toESM=(_0x355de7,_0x335296,_0x449883)=>(_0x449883=_0x355de7!=null?__create(__getProtoOf(_0x355de7)):{},__copyProps(_0x335296||!_0x355de7||!_0x355de7[_0x77c0db(0xfa)]?__defProp(_0x449883,_0x77c0db(0xd0),{'value':_0x355de7,'enumerable':!![]}):_0x449883,_0x355de7)),__toCommonJS=_0x249391=>__copyProps(__defProp({},_0x77c0db(0xfa),{'value':!![]}),_0x249391),openai_schema_service_exports={};__export(openai_schema_service_exports,{'openAiSchemaService':()=>openAiSchemaService}),module[_0x77c0db(0x107)]=__toCommonJS(openai_schema_service_exports);var import_prisma=__toESM(require(_0x77c0db(0xc7))),import_openai=__toESM(require(_0x77c0db(0xc8))),import_encryption=require(_0x77c0db(0xf6));class openAiSchemaService{static async[_0x77c0db(0x103)](){const _0x500a7f=_0x77c0db,_0x261781=await import_prisma[_0x500a7f(0xd0)][_0x500a7f(0x10a)][_0x500a7f(0xe1)]({'where':{'config_key':_0x500a7f(0xc9)}}),_0x3dc9d2=_0x261781?.['config_value'],_0x2be553=import_encryption[_0x500a7f(0xdc)][_0x500a7f(0x109)](_0x3dc9d2);openAiSchemaService[_0x500a7f(0xc8)]=new import_openai[(_0x500a7f(0xd0))]({'apiKey':_0x2be553});}static async[_0x77c0db(0xef)](){const _0x499800=_0x77c0db,_0x5a536d=await import_prisma[_0x499800(0xd0)][_0x499800(0x100)]`
          SELECT table_name
          FROM information_schema.tables
          WHERE table_schema = 'public' AND table_type = 'BASE TABLE'
        `;return _0x5a536d[_0x499800(0xe6)](_0x767e56=>_0x767e56[_0x499800(0x106)]);}static async[_0x77c0db(0x102)](_0x5db6a8){const _0x4f6856=_0x77c0db;try{const _0x385566=await import_prisma[_0x4f6856(0xd0)][_0x4f6856(0x100)]`
                SELECT column_name, data_type, is_nullable
            FROM information_schema.columns
            WHERE table_name = ${_0x5db6a8}
        `,_0x43e392=_0x385566[_0x4f6856(0xe6)](_0x1896ed=>'-\x20'+_0x1896ed['column_name']+':\x20'+_0x1896ed[_0x4f6856(0xd6)]+(_0x1896ed[_0x4f6856(0xed)]==='NO'?_0x4f6856(0xca):''))[_0x4f6856(0xcf)]('\x0a');return _0x4f6856(0xcc)+_0x5db6a8+_0x4f6856(0xf7)+_0x43e392;}catch(_0x396cb8){console[_0x4f6856(0xe4)](_0x4f6856(0xd3),_0x396cb8);throw _0x396cb8;}}static async[_0x77c0db(0xd8)](_0x79766b,_0x4a8265,_0x53e40b){const _0x52b19=_0x77c0db;try{const _0xdad8d8=await this['openai'][_0x52b19(0x105)][_0x52b19(0xfe)]({'model':_0x52b19(0xd1),'input':_0x4a8265}),_0x22cf43=_0xdad8d8[_0x52b19(0xd2)][0x0][_0x52b19(0x108)],_0x263dea=_0xdad8d8[_0x52b19(0xe5)],_0x34545b=_0x263dea[_0x52b19(0xe0)]/0x3e8*0.00002,_0x3b1857=parseFloat(_0x34545b[_0x52b19(0xe3)](0x6)),_0x4e7bbd=0x1;await import_prisma[_0x52b19(0xd0)][_0x52b19(0xfd)]`
              INSERT INTO schema_chunks (table_name, chunk, embedding, company_id, created_by)
              VALUES (${_0x79766b}, ${_0x4a8265}, ${_0x22cf43}::vector, ${_0x4e7bbd}, ${_0x53e40b})
              ON CONFLICT (table_name) DO UPDATE
              SET chunk = ${_0x4a8265},
                  embedding = ${_0x22cf43}::vector,
                  updated_at = NOW(),
                  updated_by = ${_0x53e40b}
          `,await import_prisma[_0x52b19(0xd0)][_0x52b19(0xd7)]['create']({'data':{'table_name':_0x79766b,'cost':_0x3b1857,'company_id':_0x4e7bbd,'created_by':_0x53e40b,'user_id':_0x53e40b}});}catch(_0x106456){console[_0x52b19(0xe4)]('Project\x20Sync\x20-\x20Failed:',_0x106456);throw _0x106456;}}static async[_0x77c0db(0xf3)](_0x46d3f8){const _0x476e19=_0x77c0db;try{console['log'](_0x476e19(0xec)),await import_prisma['default'][_0x476e19(0xf2)]['deleteMany']();const _0x389b87=await this['getTables']();console[_0x476e19(0xf9)]('Found\x20'+_0x389b87[_0x476e19(0xeb)]+'\x20tables\x20to\x20process');const _0xd777cf=0x1;for(const _0x3ef7bd of _0x389b87){try{console['log']('Processing\x20table:\x20'+_0x3ef7bd);const _0x3da6ab=await this[_0x476e19(0x102)](_0x3ef7bd);await import_prisma[_0x476e19(0xd0)][_0x476e19(0xf2)][_0x476e19(0xfe)]({'data':{'table_name':_0x3ef7bd,'chunk':_0x3da6ab,'created_by':_0x46d3f8,'company_id':_0xd777cf}}),console[_0x476e19(0xf9)]('✅\x20'+_0x3ef7bd+_0x476e19(0xdf));}catch(_0x23cb7b){console[_0x476e19(0xe4)](_0x476e19(0xf1)+_0x3ef7bd+':',_0x23cb7b);}}console[_0x476e19(0xf9)](_0x476e19(0xdb));}catch(_0x537ecc){console[_0x476e19(0xe4)](_0x476e19(0xd3),_0x537ecc);throw _0x537ecc;}}static async['generateVector'](_0x29be97){const _0x384e6f=_0x77c0db;try{const _0x3acfd5=await import_prisma[_0x384e6f(0xd0)][_0x384e6f(0xf2)]['findMany']({'select':{'table_name':!![],'chunk':!![]}});console[_0x384e6f(0xf9)]('Found\x20'+_0x3acfd5[_0x384e6f(0xeb)]+_0x384e6f(0x101));for(const _0x57b758 of _0x3acfd5){try{console[_0x384e6f(0xf9)](_0x384e6f(0xdd)+_0x57b758),await this['embedAndStore'](_0x57b758[_0x384e6f(0x106)],_0x57b758[_0x384e6f(0xe2)],_0x29be97),console[_0x384e6f(0xf9)]('✅\x20'+_0x57b758+_0x384e6f(0xcd));}catch(_0x173f3b){console[_0x384e6f(0xe4)]('Error\x20processing\x20table\x20'+_0x57b758+':',_0x173f3b);throw _0x173f3b;}}}catch(_0x9e787e){console[_0x384e6f(0xe4)](_0x384e6f(0xd3),_0x9e787e);throw _0x9e787e;}}static async[_0x77c0db(0xfc)](_0xf1a38a,_0x22b9f1){const _0x16dbf5=_0x77c0db;try{const _0x1e4a83=await import_prisma[_0x16dbf5(0xd0)][_0x16dbf5(0xf2)]['findFirst']({'where':{'uuid':_0xf1a38a}});if(!_0x1e4a83?.[_0x16dbf5(0x106)])throw new Error('Table\x20not\x20found');await this[_0x16dbf5(0xd8)](_0x1e4a83[_0x16dbf5(0x106)],_0x1e4a83['chunk'],_0x22b9f1),console[_0x16dbf5(0xf9)]('✅\x20'+_0x1e4a83[_0x16dbf5(0x106)]+_0x16dbf5(0xcd));}catch(_0x4aa35b){console[_0x16dbf5(0xe4)](_0x16dbf5(0xd3),_0x4aa35b);throw _0x4aa35b;}}}0x0&&(module['exports']={'openAiSchemaService':openAiSchemaService});