How 'mark as spam' and Sieve works together?

English not my native language maybe I not clearly write question.

Usually Sieve filter look like this.
If header contains something do this…

require "fileinto";
if header :contains "X-Spam" "Yes" {
 fileinto "Junk";
}

When user mark message as Spam in Mail app, on message icon appears exclamation mark and word ‘Junk’. But mail headers does not change.

Screenshot 2021-07-28 10.26.39

How to catch flags or event in SIeve script when user mark message as spam?
Could you please provide a simple example of such Sieve filter?
What should be in IF condition in the Sieve script to handle a message marked as spam?

require "fileinto";
if ??? {
 fileinto "Junk";
}