The person who has the power or choice of getting a boy or girl married is called a wali.
The first wali of a boy or girl is their father. If the father is not present, the grand -father becomes their wali. If he is not present, then the great grand-father. If none of them are present, the blood-brother becomes their wali. If he is not present, then the step-brother, i.e. brothers from one father. Thereafter, the nephew, thereafter the nephew’s son; and thereafter, the nephew’s grand-son. If none of them are present, the blood uncle becomes their wali. If he is not present, then the step-uncle, i.e. the step-brother of their father. Thereafter, the son of the blood uncle and thereafter his grand-son. Thereafter, the son of the step-uncle and thereafter his grand-son. If none of them are present, the father’s uncle becomes their wali; and thereafter his children. If the father’s uncle, his children and grand-children are not present; then the grand-father’s uncle becomes their wali. Thereafter, his children, grand-children, and great grand-children.
If none of them are present, the mother will be their wali. Thereafter, the paternal grand-mother, then the maternal grand-mother and then the maternal grand-father. Thereafter, the blood-sister and then the step-sister, i.e. sisters from one father. Thereafter, the step-brother and then the step-sister who is from one mother. Thereafter, the paternal aunt, then the maternal uncle, and then the maternal aunt.
An immature person cannot become a wali of anyone. A kaafir cannot be a wali for any Muslim, nor can a lunatic be a wali for anyone.