How to make my AI return to waypoint after I trigger chase player

Hello I am new to c# and unity anyone know how to make the AI return to walking the pre-define waypoint after the player trigger the ai chase player code ?

private void Start()
{
    transform.LookAt(waypoints[waypointIndex].position);
}

private void Update()
{
    //Check for sight and attack range
    playerInSightRange = Physics.CheckSphere(transform.position, sightRange, whatIsPlayer);
    playerInAttackRange = Physics.CheckSphere(transform.position, attackRange, whatIsPlayer);

    if (!playerInSightRange && !playerInAttackRange) Patroling();
    if (playerInSightRange && !playerInAttackRange) ChasePlayer();
    if (playerInAttackRange && playerInSightRange) AttackPlayer();
}

private void Patroling()
{
    transform.LookAt(waypoints[waypointIndex].position);

    dist = Vector3.Distance(transform.position, waypoints[waypointIndex].position);
    if (dist < 1f)
    {
        IncreaseIndex();
    }
    Patrol();
}

void Patrol()
{
    transform.Translate(Vector3.forward * agent.speed * Time.deltaTime);
}

void IncreaseIndex()
{
    waypointIndex++;
    if (waypointIndex >= waypoints.Length)
    {
        waypointIndex = 0;
    }
    transform.LookAt(waypoints[waypointIndex].position);
}
private void ChasePlayer()
{
    //patrol = false;
    agent.SetDestination(player.position);
}

,Hello I am new to c# and unity anyone know how to make the AI return to walking the pre-define waypoint after the player trigger the ai chase player code ?
private void Start()
{
transform.LookAt(waypoints[waypointIndex].position);
}

private void Update()
{
    //Check for sight and attack range
    playerInSightRange = Physics.CheckSphere(transform.position, sightRange, whatIsPlayer);
    playerInAttackRange = Physics.CheckSphere(transform.position, attackRange, whatIsPlayer);

    if (!playerInSightRange && !playerInAttackRange) Patroling();
    if (playerInSightRange && !playerInAttackRange) ChasePlayer();
    if (playerInAttackRange && playerInSightRange) AttackPlayer();
}

private void Patroling()
{
    transform.LookAt(waypoints[waypointIndex].position);

    dist = Vector3.Distance(transform.position, waypoints[waypointIndex].position);
    if (dist < 1f)
    {
        IncreaseIndex();
    }
    Patrol();
}

void Patrol()
{
    transform.Translate(Vector3.forward * agent.speed * Time.deltaTime);
}

void IncreaseIndex()
{
    waypointIndex++;
    if (waypointIndex >= waypoints.Length)
    {
        waypointIndex = 0;
    }
    transform.LookAt(waypoints[waypointIndex].position);
}
private void ChasePlayer()
{
    //patrol = false;
    agent.SetDestination(player.position);
}

Go to this script and tell me if it’s what you are looking for :