Multi-selecting checkboxes while rows are highlighted

My team and I just spent almost 2 hours discussing the right way to go about this issue.

We have a table. In this table, the rows can be selected. Each row also has a checkbox at the beginning of the row, indicating a "Show this row" functionality.

We are currently working on a check all/uncheck all/check selected/uncheck selected issue. I visualize it working like this:

enter image description here

Since one row is highlighted, when we check the header checkbox, it should only check the highlighted row:

enter image description here

Same goes for a multi-highlight:

enter image description here

enter image description here

And another:

enter image description here

enter image description here

The disagreement we are having is what to do if you have ONE row highlighted, should checking the header checkbox check that ONE row, or should it check ALL rows? The idea behind this logic is that a row can be highlighted by performing a different action on it, and therefore it's harder to de-highlight that row. Thus if 1 or fewer rows are highlighted, the header checkbox should function as a check all checkbox, rather than a check only what is selected checkbox.

For example:

enter image description here

enter image description here

Any examples or official documentation on this would be great. I personally feel as though it should only check what is highlighted and that's the end of the story, but since this is a very specific behavior, I haven't been able to find any evidence online of something similar to back up or disprove my opinion.

Thanks!