'use strict';
import { crudGetById, crudGet } from '../../meta/server/controllers/generic-controllers/crud-controller.js';
import { statusBoardErrorConstants, statusBoardStatusOkConstants } from '../../common/fd/fd-component-toolbox/status-board/status-board-constants.js';
import { statusBoardConstants } from '../../fd-app-toolbox/status-board/status-board-constants.js';
import { updateResource } from '../../meta/server/db/db.js';
import { resourceNames } from '../../../fd-toolbox/resources/resource-names.js';
import { apiBadRequestResponse, apiOkResponse } from '../../meta/server/web/responses.js';
import { logErrorRaw } from '../../../fd-toolbox/logging/loggers.js';
import { createError } from '../../../fd-toolbox/errors/errors.js';
import { convertFromPascalToCamelCase } from '../../../fd-toolbox/strings/casing-converter.js';
import { getJsonFromResponse, getArrayFromResponse, parseJsonBodyFromRequest } from '../../../fd-toolbox/lib/utils.js';

var __defProp=Object['defineProperty'],__name=(_0x262faf,_0x56dcd7)=>__defProp(_0x262faf,'name',{'value':_0x56dcd7,'configurable':!![]});async function statusboardGetRoute(_0x185c4e){const _0x1d71b0=new URL(_0x185c4e['url']),_0x3f27b9=_0x1d71b0['searchParams']['get'](statusBoardConstants['getBoardData']);let _0x5bf0b0;if(!_0x3f27b9)_0x5bf0b0=apiBadRequestResponse({'error':statusBoardErrorConstants['idIsRequired']});else {const _0x16d0ec=await crudGetById(_0x185c4e,resourceNames['statusBoard'],_0x3f27b9),_0xfa772f=await getJsonFromResponse(_0x16d0ec),_0x197e1c=await crudGet(_0x185c4e,resourceNames['statusBoardStatus']),_0x5985e9=await getJsonFromResponse(_0x197e1c),_0x38626a=await crudGet(_0x185c4e,resourceNames['statusBoardItem']),_0x1c9b63=await getJsonFromResponse(_0x38626a),_0x3534b1=getArrayFromResponse(_0x5985e9),_0x4c2541=getArrayFromResponse(_0x1c9b63);if(_0x3534b1['length']===0x21*0x6e+-0x3*0x301+-0x52b||_0x4c2541['length']===-0x9*0x432+0x6d4+-0x4a*-0x6b)_0x5bf0b0=apiBadRequestResponse({'error':statusBoardErrorConstants['boardNotFound']});else {const _0x3d7f74=_0x3534b1['map'](_0x1582b6=>{const _0x33b888=_0x4c2541['filter'](_0x472dda=>_0x472dda['statusBoardStatusId']===_0x1582b6['id']);return {..._0x1582b6,'statusBoardItemList':_0x33b888};}),_0x51e730={..._0xfa772f?.['data'],'statusBoardStatusList':_0x3d7f74};_0x5bf0b0=apiOkResponse(_0x51e730);}}return _0x5bf0b0;}__name(statusboardGetRoute,'statusboardGetRoute');async function statusboardPutRoute(_0x43ecc7){const _0x75690a=await parseJsonBodyFromRequest(_0x43ecc7);for(const _0x12c198 of _0x75690a['updatedStatusBoardData']){const _0x3b3b0a={'id':_0x12c198['id'],'priority':_0x12c198['priority']},_0x4ba3a7=await updateResource(_0x3b3b0a,_0x75690a['resourceName']);if(!_0x4ba3a7)logErrorRaw(createError(statusBoardErrorConstants['noStatusBoardFoundId']['replace']('{0}',_0x12c198['id'])));}return apiOkResponse({'message':statusBoardStatusOkConstants['priorityUSuccessfully']});}__name(statusboardPutRoute,'statusboardPutRoute');async function statusboardPostRoute(_0xbe0eb9){const _0x221c27=await parseJsonBodyFromRequest(_0xbe0eb9),_0x80f817=convertFromPascalToCamelCase(resourceNames['statusBoardItem']),_0x5c84c3={'id':_0x221c27['statusBoardItemId'],'statusBoardStatusId':_0x221c27['newParentId']},_0x22763d=await updateResource(_0x5c84c3,_0x80f817);if(!_0x22763d)logErrorRaw(createError(statusBoardErrorConstants['noItemFoundId']['replace']('{0}',_0x221c27['statusBoardItemId'])));return apiOkResponse({'message':statusBoardStatusOkConstants['parentUSuccessfully']});}__name(statusboardPostRoute,'statusboardPostRoute');

export { statusboardGetRoute, statusboardPostRoute, statusboardPutRoute };
