Character rotation help needed.

I’m making a platformer game with A and D as the controls for left and right navigation. When the player presses the “A” key the character is supposed to rotate 180 degrees from their current facing point and start moving in the other direction(left), however the code does the rotation but the character ends up going backwards (facing left but going right)

I cant seem to figure out how to fix it any help would be awesome.
the code that I’m using to handle the rotation is:

if (Input.GetKeyDown (KeyCode.A))
{  
      transform.Rotate(0,180,0);
}

if (Input.GetKeyDown (KeyCode.A))
{
transform.Rotate(0,180,0);
transform.position += transform.forward * speed;
}

you should always move relative to the local forward and up and right to make sure you dont end up going the wrong way.
I.E. when you rotate the front doesnt become the back because forward rotates with you.