function matchUpActions({
  tournamentRecord,
  drawDefinition,
  matchUpId,
  drawId,
}) {
  if (!tournamentRecord) return { error: MISSING_TOURNAMENT_RECORD };
  if (!drawId) {
    // if matchUp did not have context, find drawId by brute force
    const { matchUps } = allTournamentMatchUps({ tournamentRecord });
    drawId = matchUps.reduce((drawId, candidate) => {
      return candidate.matchUpId === matchUpId ? candidate.drawId : drawId;
    }, undefined);
    const events = tournamentRecord.events || [];
    const drawDefinitions = events
      .map((event) => event.drawDefinitions || [])
      .flat();
    drawDefinition = drawDefinitions.reduce((drawDefinition, candidate) => {
      return candidate.drawId === drawId ? candidate : drawDefinition;
    }, undefined);
  }

  if (drawId) {
    return drawEngineMatchupActions({ drawDefinition, matchUpId });
  } else {
    return { error: DRAW_DEFINITION_NOT_FOUND };
  }
}
/**
 *
 * return an array of all validActions for a given matchUp
 *
 * @param {object} tournamentRecord - provided automatically if tournamentEngine state has been set
 * @param {string} drawId - if provided then drawDefinition will be found automatically
 * @param {object} drawDefinition
 * @param {string} matchUpId - id of matchUp for which validActions will be returned
 *
 */
return an array of all validActions for a given matchUp
@param {object} tournamentRecord - provided automatically if tournamentEngine state has been set
@param {string} drawId - if provided then drawDefinition will be found automatically
@param {object} drawDefinition
@param {string} matchUpId - id of matchUp for which validActions will be returned
return an array of all validActions for a given matchUp @param { object } tournamentRecord - provided automatically if tournamentEngine state has been set @param { string } drawId - if provided then drawDefinition will be found automatically @param { object } drawDefinition @param { string } matchUpId - id of matchUp for which validActions will be returned
function matchUpActions({
  tournamentRecord,
  drawDefinition,
  matchUpId,
  drawId,
}) {
  if (!tournamentRecord) return { error: MISSING_TOURNAMENT_RECORD };
  if (!drawId) {
    const { matchUps } = allTournamentMatchUps({ tournamentRecord });
    drawId = matchUps.reduce((drawId, candidate) => {
      return candidate.matchUpId === matchUpId ? candidate.drawId : drawId;
    }, undefined);
    const events = tournamentRecord.events || [];
    const drawDefinitions = events
      .map((event) => event.drawDefinitions || [])
      .flat();
    drawDefinition = drawDefinitions.reduce((drawDefinition, candidate) => {
      return candidate.drawId === drawId ? candidate : drawDefinition;
    }, undefined);
  }
  if (drawId) {
    return drawEngineMatchupActions({ drawDefinition, matchUpId });
  } else {
    return { error: DRAW_DEFINITION_NOT_FOUND };
  }
}
function matchUpActions ( { tournamentRecord , drawDefinition , matchUpId , drawId , } ) { if ( ! tournamentRecord ) return { error : MISSING_TOURNAMENT_RECORD } ; if ( ! drawId ) { const { matchUps } = allTournamentMatchUps ( { tournamentRecord } ) ; drawId = matchUps . reduce ( ( drawId , candidate ) => { return candidate . matchUpId === matchUpId ? candidate . drawId : drawId ; } , undefined ) ; const events = tournamentRecord . events || [ ] ; const drawDefinitions = events . map ( ( event ) => event . drawDefinitions || [ ] ) . flat ( ) ; drawDefinition = drawDefinitions . reduce ( ( drawDefinition , candidate ) => { return candidate . drawId === drawId ? candidate : drawDefinition ; } , undefined ) ; } if ( drawId ) { return drawEngineMatchupActions ( { drawDefinition , matchUpId } ) ; } else { return { error : DRAW_DEFINITION_NOT_FOUND } ; } }
return an array of all validActions for a given matchUp
 @param {object} tournamentRecord - provided automatically if tournamentEngine state has been set
 @param {string} drawId - if provided then drawDefinition will be found automatically
 @param {object} drawDefinition
 @param {string} matchUpId - id of matchUp for which validActions will be returned
return an array of all validActions for a given matchUp @param { object } tournamentRecord - provided automatically if tournamentEngine state has been set @param { string } drawId - if provided then drawDefinition will be found automatically @param { object } drawDefinition @param { string } matchUpId - id of matchUp for which validActions will be returned
// if matchUp did not have context, find drawId by brute force