The chemical structure of the Class 0 protostellar envelope NGC 1333 IRAS 4A