'use strict';
import { promises } from 'fs';
import * as _0x128a09 from '@googleapis/sheets';
import { paths } from '../constants/paths-constants.js';
import { enricherErrorMessages } from '../constants/enricher-error-message-constants.js';
import { parseJson } from '../../../fd-toolbox/lib/utils.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';

var __defProp=Object['defineProperty'],__name=(_0x3b6b16,_0x47f6d8)=>__defProp(_0x3b6b16,'name',{'value':_0x47f6d8,'configurable':!![]});let spreadsheetsSingleton;async function initSpreadsheetConfig(_0x57b1b2){const _0x22dc4c={'keyFilename':paths['serviceAccountKey'],'scopes':['https://www.googleapis.com/auth/spreadsheets'],'spreadsheetId':_0x57b1b2['spreadsheetId']??'','sheetName':_0x57b1b2['sheetName']??'',..._0x57b1b2};promises['writeFile'](paths['spreadsheetConfig'],JSON['stringify'](_0x22dc4c,void(0x11e+-0x1713+0x15f5),0x22b2+0x162e+-0x38dc*0x1));}__name(initSpreadsheetConfig,'initSpreadsheetConfig');async function getSpreadsheetConfig(){const _0xe5f607=await promises['readFile'](paths['spreadsheetConfig'],'utf-8');return parseJson(_0xe5f607);}__name(getSpreadsheetConfig,'getSpreadsheetConfig');async function readSpreadsheetValues(_0x189ba2,_0x23db19){const _0x322642=await getSpreadsheets(),_0x3ddd7c=await _0x322642['values']['get']({'spreadsheetId':_0x189ba2,'range':_0x23db19});return _0x3ddd7c['data']['values']??[[]];}__name(readSpreadsheetValues,'readSpreadsheetValues');async function writeSpreadsheetValues(_0x91c4c1,_0x3e37bc,_0x961f7f){const _0x5e511a=await getSpreadsheets(),_0x485a87=await _0x5e511a['values']['update']({'spreadsheetId':_0x91c4c1,'range':_0x3e37bc,'valueInputOption':'RAW','requestBody':{'values':_0x961f7f}});return _0x485a87['data']['updatedCells'];}__name(writeSpreadsheetValues,'writeSpreadsheetValues');async function getColumnIndex(_0x2c87b5,_0x47682a,_0x243995){const _0x4a525e=await getHeaderRows(_0x2c87b5,_0x47682a),_0x33a50c=_0x4a525e?.['indexOf'](_0x243995);if(_0x33a50c===-(-0x2*-0x89c+-0x12fe+0x5b*0x5))throw createError(enricherErrorMessages['columnNotFound']['replace']('{0}',_0x243995));return _0x33a50c;}__name(getColumnIndex,'getColumnIndex');async function getHeaderRows(_0x5226c1,_0x5f5ae4){const _0x165571=await readSpreadsheetValues(_0x5226c1,_0x5f5ae4+'!1:1'),_0x15d2a3=_0x165571?.['flat']();return _0x15d2a3;}__name(getHeaderRows,'getHeaderRows');async function getSpreadsheets(){if(!spreadsheetsSingleton)await initSpreadsheets();return spreadsheetsSingleton;}__name(getSpreadsheets,'getSpreadsheets');async function initSpreadsheets(){const _0x3d38f5=await getSpreadsheetConfig(),_0x357325=new _0x128a09['auth']['GoogleAuth']({'keyFilename':_0x3d38f5['keyFilename'],'scopes':_0x3d38f5['scopes']});spreadsheetsSingleton=_0x128a09['sheets']({'version':'v4','auth':_0x357325})['spreadsheets'];}__name(initSpreadsheets,'initSpreadsheets');

export { getColumnIndex, getHeaderRows, getSpreadsheetConfig, initSpreadsheetConfig, readSpreadsheetValues, writeSpreadsheetValues };
