If the person attacks you with a base ball bat then that is illegal. Also trying to hit back might tie you in the same category as you are not supposed to take law in your own hands and retaliate. The best thing to do is to report the case to the respective authority and let them deal with him.
If someone attacks you with a baseball bat, you have the right to defend yourself. What you do not have the right is to go beyond defending yourself. Say he swings, you knock him and take his bat. You should stop at this point. No more hitting unless he comes at you again.
You have the right to defend yourself, but you don't have the right to beat the tar out of the attacker. For example, you are attacked by someone wielding a bat. You avoid the initial attack and punch the attacker in the nose. So far, so good. As a result of your punch, the attacker stops attacking. If you punch again, you are now the attacker and your second punch isn't self defense. You could be charged.