import { get } from 'lit-translate' ; import { identity , LogDetailBase } from '../../foundation.js' ; import { getAdjacentClass , iec6185074 , validateChildren , } from './foundation.js' ; async function getMandatoryDataObject ( base ) { const lnodeclasses = getAdjacentClass ( await iec6185074 , base ) ; return lnodeclasses . flatMap ( lnodeclass => Array . from ( lnodeclass . querySelectorAll ( 'DataObject[presCond="M"]' ) ) ) ; } async function missingMandatoryChildren ( lnodetype , lnClass ) { const errors = [ ] ; const mandatorydos = await ( await getMandatoryDataObject ( lnClass ) ) . map ( DO => DO . getAttribute ( 'name' ) ! ) ; mandatorydos . forEach ( mandatorydo => { if ( ! lnodetype . querySelector ( `DO[name="${ mandatorydo }"]` ) ) errors . push ( { title : get ( 'validator.templates.mandatoryChild' , { tag : 'lnClass' , id : lnClass , childTag : 'DO' , childId : mandatorydo , } ) , message : `${ identity ( lnodetype ) } > ${ mandatorydo }` , } ) ; } ) ; return errors ; } export async function lNodeTypeValidator ( element ) { const errors = [ ] ; const lnClass = element . getAttribute ( 'lnClass' ) ; if ( ! lnClass ) return [ { title : get ( 'validator.templates.missingAttribute' , { attr : 'lnClass' , element : element . tagName , } ) , message : `${ identity ( element ) }` , } , ] ; const missingChildren = await missingMandatoryChildren ( element , lnClass ) ; const issuesChildren = await validateChildren ( element ) ; return errors . concat ( missingChildren , issuesChildren ) ; }