Glow LED when pb1 is pressed and pb2 to turn it off, if pb2 is not pressed in 20 sec than led start blinking until pb2 pressed. Please help

int ledpin = 5;
int pushbutton1 = 8;
int pushbutton2 = 9;
boolean lastbuttonstate1 = LOW;
boolean lastbuttonstate2 = LOW;

void setup()
{
pinMode(ledpin,OUTPUT);
pinMode(pushbutton1,INPUT);
pinMode(pushbutton2,INPUT);
}

void loop()
{
if ( digitalRead(pushbutton1)== HIGH && digitalRead(pushbutton2) == LOW && lastbuttonstate1 == LOW )
{
digitalWrite (ledpin,HIGH) ;
}
delay(20000);
{
beep();

}


if( digitalRead(pushbutton1)== LOW && digitalRead(pushbutton2) == HIGH  && lastbuttonstate2 == LOW )
{
  digitalWrite (ledpin,LOW) ;

}

}
void beep()
{
digitalWrite(ledpin, HIGH);

delay(1000);
digitalWrite(ledpin, LOW);
delay(1000);

}

i think the code will need to keep track of a "state".

in the first state, it monitors pb1. when pressed it captures a timestamp (i.e. timestamp = millis();), turns on the LED and changes to state 2

in the 2nd state, it monitors pb2 and checks if the time has expired: if (millis() - timestamp) > 20,000). if pb2 is pressed, turn off the LED and change to change 1st state. if the time expires, change to a 3rd state that uses a timer to toggle the LED on/off and monitors pb2. when pb2 is pressed, make sure the LED is off and change to the 1st state

Hello matrica1996
What is the desired function of your sketch?
Take some time and describe the desired function of the sketch in simple words and this very simple.
Have a nice day and enjoy coding in C++.