
555 So.2d 81 (1989)
Billy A. PHILLIPS; Bonnie Phillips; and Derrick Phillips, who sues By and Through his parents and next friends, Billy A. Phillips and Bonnie Phillips
v.
Debbie C. THOMAS and Louise R. Pittman.
87-1528.
Supreme Court of Alabama.
July 21, 1989.
*82 Richard C. Hamilton and Mark S. Carter of Hamilton, Estes & Carter, Phenix City, for appellants.
William Prendergast, James E. Long and Sharon E. Ficquette, Asst. Attys. Gen., for appellees.

ON APPLICATION FOR REHEARING
HORNSBY, Chief Justice.
The original opinion is withdrawn and the following opinion is substituted therefor.
This is a sovereign immunity case which involves a negligence action filed by Bonnie and Billy Phillips, in their own right and on behalf of their 13-month-old son Derrick Phillips, against various defendants, including the appellees, Debbie C. Thomas and Louise R. Pittman. The plaintiffs allege that on March 6, 1986, Derrick Phillips wandered from the playground area of the Jack and Jill Nursery and Day Care Center and fell into water that had collected on a covering over a swimming pool located on the opposite side of the day care center. The plaintiffs further allege that Derrick Phillips suffered serious personal injury as a result of the accident.
At the time of the accident, both Thomas and Pittman were state employees working with the Alabama Department of Human Resources. Thomas was assigned to the Office of Day Care, and Pittman served as the director of the Family and Children's Services Division of the Department. The plaintiffs allege that Thomas and Pittman negligently performed their official duties and thereby caused the injuries suffered by Derrick Phillips.
On April 21, 1988, the trial court issued an order dismissing Pittman and entered a judgment on the pleadings for Thomas, on the basis of sovereign immunity under Article I, § 14, Alabama Constitution of 1901. Final judgment was entered as to Pittman and Thomas on October 20, 1988, pursuant *83 to Rule 54(b), Ala.R.Civ.P. This appeal followed.
The ultimate question is whether the trial court erred in granting Pittman's motion to dismiss and Thomas's motion for judgment on the pleadings on the basis of sovereign immunity as provided by Article I, § 14, Alabama Constitution of 1901. This question is answered through the resolution of two subissues: 1) whether the plaintiffs' suit against the appellees is, in effect, one against the State, thus affording the appellees absolute immunity from suit; and, if not, then 2) whether the appellees are entitled to substantive or qualified immunity from the plaintiffs' claim because they were engaged in the exercise of a discretionary public function.
I. When Sovereign Immunity is not Available. We first consider whether the appellees are entitled to sovereign immunity of any kind. This Court has recognized that a state officer or employee may not escape individual tort liability by "`arguing that his mere status as a state official cloaks him with the state's constitutional immunity.'" Barnes v. Dale, 530 So.2d 770, 781 (Ala.1988) (quoting Tort Liability of State Officials in Alabama, 35 Ala.L.Rev. 153 (1984).) Clearly, a state officer or employee is not protected by § 14 when he acts willfully, maliciously, illegally, fraudulently, in bad faith, beyond his authority, or under a mistaken interpretation of the law. See Lumpkin v. Cofield, 536 So.2d 62, 65 (Ala.1988); Barnes, 530 So.2d at 782; DeStafney v. University of Alabama, 413 So.2d 391, 393 (Ala.1981); Gill v. Sewell, 356 So.2d 1196, 1198 (Ala. 1978); Unzicker v. State, 346 So.2d 931, 933 (Ala.1977); and St. Clair County v. Town of Riverside, 272 Ala. 294, 296, 128 So.2d 333, 334 (1961). In addition, a state official is not immune from a suit to compel the performance of a legal duty, a suit to enjoin the enforcement of an unconstitutional law, a suit to compel the performance of a ministerial act, or a suit brought under the Declaratory Judgment Act. See DeStafney, 413 So.2d at 393 (citing Aland v. Graham, 287 Ala. 226, 229, 250 So.2d 677, 679 (1971)); Gill, 356 So.2d at 1198; and Milton v. Espey, 356 So.2d 1201, 1203 (Ala.1978). Because such circumstances are not presented in this case, we move to our discussion of absolute immunity.
II. Absolute Immunity. Article I, § 14, Alabama Constitution of 1901, is the basis for sovereign immunity in this State, and that section provides that "the State of Alabama shall never be made a defendant in any court of law or equity." Under this provision, the State and its agencies have absolute immunity from suit in any court. Barnes, 530 So.2d at 781; Hickman v. Dothan City Bd. of Educ., 421 So.2d 1257, 1258 (Ala.1982); Gill, 356 So.2d at 1198; and Milton, 356 So.2d at 1202. State officers and employees, in their official capacities and individually, also are absolutely immune from suit when the action is, in effect, one against the State. Barnes, 530 So.2d at 781; DeStafney, 413 So.2d at 393; Gill, 356 So.2d at 1198; and Milton, 356 So.2d at 1202. In determining whether an action against a state officer or employee is, in fact, one against the State, this Court will consider such factors as the nature of the action and the relief sought. See DeStafney, 413 So.2d at 395; and Milton, 356 So.2d at 1202. In addition, we have recognized the following rules with respect to absolute immunity in a negligence action to recover for personal injury, like that filed by the plaintiffs in this case:
"`[A] claim for personal injury based upon the alleged negligent conduct of a State employee, even when committed in the line and scope of employment, is not within the ambit of § 14's protection. Such a claim, by virtue of its nature and the relief demanded, in no way seeks to circumvent the prohibition of § 14. Any state interest affected by the suit is far too incidental to supply the requisite nexus for extension of constitutional immunity to the individual employee defendant.'"
Barnes, 530 So.2d at 783 (quoting DeStafney, 413 So.2d at 395). There can be no question under the holdings of Barnes and DeStafney that the nature of the present action and the relief sought herein are not the kind that would afford either Pittman *84 or Thomas absolute immunity from suit. Thus, we move to the question of whether the appellees are entitled to qualified or substantive immunity.
III. Substantive Immunity. Qualified or substantive immunity is available to a state officer or employee acting within the general scope of his authority, but only when certain circumstances are present. "[W]hether a particular defendant is engaged in a protected discretionary function and is thereby immune from liability for injuries he causes is a question of law to be decided by the trial court." Grant v. Davis, 537 So.2d 7, 8 (Ala.1988).
This Court has adopted the tort liability rule for public officers found in Restatement (Second) of Torts, which provides as follows:
"(1) Except as provided in this Section a public officer is not immune from tort liability.
"(2) A public officer acting within the general scope of his authority is immune from tort liability for an act or omission involving the exercise of a judicial or legislative function.
"(3) A public officer acting within the general scope of his authority is not subject to tort liability for an administrative act or omission if

"(a) he is immune because engaged in the exercise of a discretionary function,

"(b) he is privileged and does not exceed or abuse the privilege, or
"(c) his conduct was not tortious because he was not negligent in the performance of his responsibility."
Restatement, § 895D, "Public Officers" (1977) (emphasis added); see also Barnes, 530 So.2d at 783; and DeStafney, 413 So.2d at 393. In determining what is a discretionary function, we have recognized certain factors that may be considered, including the following:
"[1] the nature and importance of the function that the officer is performing; the extent to which passing judgment on the exercise of discretion will amount necessarily to passing judgment on the conduct of a coordinate branch of government; [3] the extent to which the imposition of liability would impair the free exercise of discretion by the officer; [4] the extent to which the ultimate financial responsibility will fall on the officer; [5] the likelihood that harm will result to members of the public if the action is taken; [6] the nature and seriousness of the type of harm that may be produced; and [7] the availability to the injured party of other remedies and other forms of relief."
Barnes, 530 So.2d at 784 (citing the Restatement, § 895D, comment f).
In the present case, the plaintiffs allege that Pittman and Thomas were negligent in licensing the day care center at which Derrick Phillips was injured, that Thomas was also negligent in her inspection of the facility, and that Pittman was negligent in her training and supervision of Thomas.[1] We must now determine whether these functions were discretionary in nature. In doing so, we refer, once again, to our prior decisions in Barnes, DeStafney, and Gill.
In Barnes, 530 So.2d 770 (Ala.1988), this Court held, as a matter of law, that the defendant employees of a state mental hospital were immune from suit for wrongful death resulting from the alleged negligent treatment and release of a patient because they were engaged in the exercise of a discretionary public function at the time of the patient's admission and discharge. Similarly, in Gill, 356 So.2d 1196 (Ala. 1978), we held that the director of a work release center was immune from suit for his decision to release a convicted felon who subsequently shot a police officer. On the other hand, in DeStafney, 413 So.2d 391 (Ala.1981), we held that a state day care employee was not immune from suit for her alleged negligence in allowing a child to fall from playground equipment *85 while in her care. In DeStafney, we reasoned that the defendant's duty was one of due care and was not one requiring difficult decision making, like the duty accompanying a discretionary public function.
With respect to the claim against Pittman for negligent training and supervision of Thomas, we have little difficulty concluding that the exercise of such functions is, for the most part, discretionary in nature and, to that extent, affords Pittman substantive immunity from suit. These duties while perhaps affirmative ones, require constant decision making and judgment on the part of the supervisor or trainer. Cf., Grant, 537 So.2d 7 (Ala.1988); and Milton, 356 So.2d 1201 (Ala. 1978). At the same time, we recognize that these functions can be composed of ministerial acts, which, if performed negligently, are actionable. See DeStafney, 413 So.2d 391 (Ala. 1981). However, absent some evidence that Pittman negligently performed a ministerial part of these functions or that she acted willfully, maliciously, illegally, fraudulently, in bad faith, beyond her authority, or under a mistaken interpretation of the law, Pittman will be entitled to § 14 immunity on these claims. Cf., id.; and Unzicker, 346 So.2d 931 (Ala.1977).
With respect to the claims against Thomas and Pittman for negligent licensing of the day care center and the claim against Thomas for negligent inspection of the center, we refer to the statutes governing these functions. Sections 38-7-3 through 38-7-8, Code 1975, set forth the role of the Department of Human Resources in issuing or renewing a license to operate a day care center. Section 38-7-4 provides, in part, as follows:
"Any person, group of persons or corporation who or which receives children or arranges for care or placement of one or more children unrelated to the operator shall apply for a license or for approval to operate one of the types of child-care facilities defined in this chapter. Application for such license or approval to operate a child-care facility shall be made to the department in the manner and on forms prescribed by it. The department, upon receiving such application, shall examine the premises of the child-care facility, including buildings, equipment, furnishings and appliances thereof and shall investigate the persons responsible for the care of children therein. If, upon such examination of the facility and investigation of the persons responsible for care of children, the department is satisfied that the facility and the responsible persons reasonably meet standards prescribed for the type of childcare facility for which application is made, the department shall issue a license or an approval in the proper form, designating on said license or approval the type of child-care facility and except for a child-placing agency, the number of children to be served at any one time." (Emphasis added.)
As concerns the inspection of day care facilities, § 38-7-11 provides, in part, as follows:
"The department shall have the right and its authorized representatives shall be afforded reasonable opportunity, to inspect any child-care facility seeking a license or an approval or a six-month permit pursuant to this chapter, any child-care facility seeking a renewal of a license or an approval or a six-month permit pursuant to this chapter and any child-care facility which is operating under a license or an approval or a six-month permit issued pursuant to this chapter. Such inspection shall include, but not be limited to, premises, services, personnel, program, accounts and records, interviews with agents and employees of the child-care facility being inspected and interviews with any child or other person within the custody or control of said child-care facility. Such inspection shall be made at any reasonable time, without prior notice, and as often as necessary to enforce and administer the provisions of this chapter. It shall be the duty of the department, through its agents, to conduct the inspections authorized hereinabove. If any such inspection of a licensed or approved child-care facility discloses any condition, *86 deficiency, dereliction or abuse which is, or could be, hazardous to the health, the safety or the physical, moral or mental well-being of the children in the care of the child-care facility being inspected, the same shall at once be brought to the attention of the department, and the department shall have the power to revoke without notice the license or approval or six-month permit of such child-care facility." (Emphasis added.)
Again, we recognize that these duties, although affirmative in nature, do require a considerable degree of discretion within department guidelines. Cf., Grant, 537 So.2d 7, 10 (Ala.1988). Again, we also recognize that they can be composed of ministerial components. For example, if the department guidelines require that specific steps be taken in conducting an inspection or specify the manner in which they are to be taken, the performance of such steps is not discretionary, and, thus, a state employee's negligence with respect to those particular ministerial acts is actionable.
This Court has held that qualified immunity from suit for negligence arising out of a discretionary act is an affirmative defense which must be raised and proved by the defendant. See Bell v. Chisom, 421 So.2d 1239 (Ala.1982); and Hickman, 421 So.2d 1257 (Ala.1982). As such, a plaintiff's complaint against a state official or employee, seeking damages for personal injury arising out of the negligent performance of the defendant's official duties, does state a valid cause of action, and, as such, will survive the defendant's motions to dismiss and for judgment on the pleadings, even if the defendant raises the affirmative defense of qualified immunity. The summary judgment stage, then, becomes the step at which the court must determine whether the case should proceed forward, and at which the defendant must meet his burden of showing that the alleged negligence arose out of a discretionary or nonministerial act, in order to avail himself of qualified immunity from suit.
In the present case, the record indicates that by the time the trial court granted Pittman's motion to dismiss and Thomas's motion for judgment on the pleadings, the plaintiffs had introduced evidence in support of their argument that the appellees were not entitled to qualified immunity from suit. Under A.R.Civ.P. 12(c), "[i]f, on a motion for judgment on the pleadings, matters outside the pleadings are presented to and not excluded by the court, the motion shall be treated as one for summary judgment." Similarly, A.R.Civ.P. 12(b) provides that "[i]f, on a motion asserting the defense numbered (6) to dismiss for failure of the pleading to state a claim upon which relief can be granted, matters outside the pleading are presented to and not excluded by the court, the motion shall be treated as one for summary judgment." Therefore, because the trial court considered matters outside the pleadings when it ruled on the appellees' motions, the motions became motions for summary judgment.
In this case, the plaintiffs do not allege, nor do they argue, that Pittman was negligent with respect to a ministerial act or any other circumstance that would remove her from the shield of qualified immunity. Therefore, the trial court's entry of judgment in her favor was proper. However, with respect to Thomas, the plaintiffs' evidence includes an inspection sheet completed by Thomas, personally, when she conducted an inspection of the day care center, on which she answered "yes" to the question concerning whether the pool on the premises was enclosed with a fence. The plaintiffs claim that it was not. This evidence clearly establishes the fact that Thomas's alleged negligence arose out of the performance of a ministerial act, and, therefore, that Thomas is not entitled to qualified immunity from suit. Therefore, the trial court's entry of judgment in Thomas's favor was erroneous.
Accordingly, we hereby reverse the trial court's entry of summary judgment in favor of Thomas on the issue of qualified immunity; affirm the judgment in favor of Pittman on this issue; and remand for proceedings consistent with this opinion.
*87 APPLICATION FOR REHEARING GRANTED; ORIGINAL OPINION WITHDRAWN; OPINION SUBSTITUTED.
AFFIRMED IN PART, REVERSED IN PART, AND REMANDED.
MADDOX, ALMON, ADAMS and STEAGALL, JJ., concur.
NOTES
[1]  The complaint avers that Ms. Pittman and Ms. Thomas were negligent, reckless, and wanton in the performance of their official duties. On appeal, however, the plaintiffs allege error only in the trial court's rulings concerning the issue of negligence. Therefore, our analysis is limited to that context.
