Under what conditions could someone use the insanity defense?

Under what conditions could someone use the insanity defense? Support your response with factual information from your textbook or additional resources.