enforceManualFlags :: Tree QGoalReasonChain -> Tree QGoalReasonChain
enforceManualFlags = trav go
  where
    go (FChoiceF qfn gr tr True ts) = FChoiceF qfn gr tr True $
      let c = toConflictSet (Goal (F qfn) gr)
      in  case span isDisabled (P.toList ts) of
            ([], y : ys) -> P.fromList (y : L.map (\ (b, _) -> (b, Fail c ManualFlag)) ys)
            _            -> ts -- something has been manually selected, leave things alone
      where
        isDisabled (_, Fail _ (GlobalConstraintFlag _)) = True
        isDisabled _                                    = False
    go x                                                   = x

-- | Require installed packages.
enforceManualFlags :: Tree QGoalReasonChain -> Tree QGoalReasonChain
enforceManualFlags = trav go
  where
    go (FChoiceF qfn gr tr True ts) = FChoiceF qfn gr tr True $
      let c = toConflictSet (Goal (F qfn) gr)
      in  case span isDisabled (P.toList ts) of
            ([], y : ys) -> P.fromList (y : L.map (\ (b, _) -> (b, Fail c ManualFlag)) ys)
            _            -> ts -- something has been manually selected, leave things alone
      where
        isDisabled (_, Fail _ (GlobalConstraintFlag _)) = True
        isDisabled _                                    = False
    go x                                                   = x

-- | Require installed packages.
enforceManualFlags = trav go
  where
    go (FChoiceF qfn gr tr True ts) = FChoiceF qfn gr tr True $
      let c = toConflictSet (Goal (F qfn) gr)
      in  case span isDisabled (P.toList ts) of
            ([], y : ys) -> P.fromList (y : L.map (\ (b, _) -> (b, Fail c ManualFlag)) ys)
            _            -> ts -- something has been manually selected, leave things alone
      where
        isDisabled (_, Fail _ (GlobalConstraintFlag _)) = True
        isDisabled _                                    = False
    go x                                                   = x

-- | Require installed packages.