
98 Cal.Rptr.2d 44 (2000)
82 Cal.App.4th 171
Raymond DUNKIN, Plaintiff and Appellant,
v.
Lisa BOSKEY, Defendant and Respondent.
No. A087866.
Court of Appeal, First District, Division One.
July 14, 2000.
*47 Furtado, Jaspovice & Simons, Richard J. Simons, Esq., Hayward, for Plaintiff and Appellant.
The Castleman Law Firm, Jacqueline C. Hamilton, Esq., San Francisco, Terrence P. Murphey, Esq., for Defendant and Respondent.
SWAGER, J.
Appellant Raymond Dunkin's action against respondent Lisa Boskey for breach of contract was dismissed after the trial court sustained a demurrer without leave to amend. We conclude that an agreement between the parties to grant appellant paternity rights to a child conceived *48 by artificial insemination is binding, and may be enforced to the extent of an action for unjust enrichment. We therefore reverse the judgment in part and remand the case to the trial court.

STATEMENT OF FACTS AND PROCEDURAL HISTORY
Following dismissal of his action for declaratory relief to establish his paternity and custody rights to a daughter born to respondent, appellant filed causes of action for breach of contract against respondent and professional negligence against defendant Pacific Fertility Medical Center (hereafter Pacific Fertility) in the present case. Appellant's first amended complaint alleged that he and respondent "cohabitated" between 1993 and 1998, but "were never married." Appellant had suffered from testicular cancer which had left him sterile. In 1995 he and respondent consulted with Pacific Fertility for the purpose of conceiving a child by artificial insemination.
On July 15, 1995, appellant and respondent entered into a written contract, drafted by Pacific Fertility and entitled "Consent for Artificial Insemination" (hereafter the agreement), to "create a child by the use of artificial insemination ... through the ... use of the sperm of an anonymous donor." Pursuant to the agreement, which specifies that it is "governed by the Laws of the State of California," appellant and respondent as "male partner and female partner" respectively, acknowledged "our obligation to care for and support and educate and otherwise treat and consider any child born as the result of such artificial insemination in all respects as though it were our natural child." They further promised to "never allege in any proceeding that the child or children, is other than legitimate, and the male partner and the female partner acknowledge that the child shall be the lawful child of both the mother and the male partner, and that neither of them shall assert a contrary position in any subsequent proceeding." According to the first amended complaint, Pacific Fertility advised appellant that "he would be treated by the law as the acknowledged and legal parent of the child to be born through the artificial insemination procedure, and that he need take no further action to have full rights of visitation, custody and other parental rights as to the child."
On April 22, 1996, respondent gave birth to a daughter. Appellant was named as the "Father of Child" on the birth certificate.[1] After the birth, appellant cared for her on a daily basis and "held out the child as his natural child," but he and respondent never married, and appellant did not adopt the child. In March of 1998, respondent "terminated her cohabitation and relationship" with appellant, and moved with the child from California to Wisconsin. Respondent thereafter denied appellant any custody or visitation with the child.
In April of 1998, respondent commenced a declaratory relief action in Wisconsin to terminate any rights of appellant to paternity, custody or visitation. Appellant subsequently filed a complaint in California to establish his paternity and custody rights to the child. The trial court dismissed appellant's action in California,[2] based upon a finding that he lacked standing to "sue for custody and visitation." After the instant breach of contract action against respondent by appellant was also dismissed, this appeal ensued.

DISCUSSION
Appellant argues that the trial court erred by finding that he has no right to enforce the agreement. He claims that the agreement "with his domestic partner" to "together raise" a child is not illegal or *49 otherwise unenforceable. He also maintains that he "should have been permitted to amend his complaint" to allege causes of action for intentional infliction of emotional distress and unjust enrichment. Respondent contends that appellant's action is barred by the res judicata effect of the prior judgment, and the agreement is unenforceable for public policy reasons.
Our review is governed by wellsettled principles. "When reviewing an order sustaining a demurrer without leave to amend, this court must treat the demurrer as admitting all properly pleaded facts, but not contentions, deductions or conclusions of fact or law. We must read the complaint as a whole and give it a reasonable interpretation." (Koch v. Rodlin Enterprises (1990) 223 Cal.App.3d 1591, 1595, 273 Cal.Rptr. 438.) "Regardless of the label attached to the cause of action, we must examine the complaint's factual allegations to determine whether they state a cause of action on any available legal theory. Reversible error is committed if the facts alleged show entitlement to relief under any possible legal theory." (Shaolian v. Safeco Ins. Co. (1999) 71 Cal.App.4th 268, 271, 83 Cal.Rptr.2d 702.) And, "If the complaint, liberally construed, can state a cause of action, or if it is reasonably possible that the plaintiffs can cure the complaint by amendment, the trial court should not sustain a demurrer without leave to amend." (Koch v. Rodlin Enterprises, supra, at p. 1595, 273 Cal.Rptr. 438.)

I. The Res Judicata Effect of the Judgment in the Declaratory Relief Action.
Respondent insists that dismissal of appellant's prior complaint to establish parental relationship precludes the present action under principles of res judicata. Appellant's prior action was brought in the family court under the Uniform Parentage Act (UPA) (Fam.Code, § 7600 et seq.), to determine whether a parent and child relationship exists.[3] Appellant claimed he was the child's parent, and requested custody and visitation rights. Following a hearing, the trial court found that it lacked "subject matter jurisdiction over child custody and visitation with respect to [the child]," and appellant "lacks standing to sue for custody and visitation of the child who was conceived of artificial insemination ... with another man's sperm." No appeal was taken from the prior judgment, and it became final.[4]
Under the doctrine of res judicata, "parties to a prior proceeding are precluded from relitigating issues determined in the prior proceeding. (See 7 Witkin, Cal. Procedure [(3d ed. 1985)] Judgment, §§ 253-254.)" (Bob Baker Enterprises, Inc. v. Chrysler Corp. (1994) 30 Cal.App.4th 678, 686, 36 Cal.Rptr.2d 12.) A prior judgment "`... "operates as an estoppel or conclusive adjudication as to such issues in the second action as were actually litigated and determined in the first action." [Citation.]' (Clark v. Lesher (1956) 46 Cal.2d 874, 880 [299 P.2d 865].)" (Sabek, Inc. v. Engelhard Corp. (1998) 65 Cal.App.4th 992, 997, 76 Cal.Rptr.2d 882.) The doctrine "rests upon the ground that the party to be affected, or some other with whom he is in privity, has litigated, or had an opportunity to litigate the same matter in a former action in a court of competent jurisdiction, and should not be *50 permitted to litigate it again to the harassment and vexation of his opponent. Public policy and the interest of litigants alike require that there be an end to litigation." (Panos v. Great Western Packing Co. (1943) 21 Cal.2d 636, 637, 134 P.2d 242; see also Citizens for Open Access etc. Tide, Inc. v. Seadrift Assn. (1998) 60 Cal. App.4th 1053, 1065, 71 Cal.Rptr.2d 77.)
"`A prior determination by a tribunal will be given collateral estoppel effect when (1) the issue is identical to that decided in a former proceeding; (2) the issue was actually litigated and (3) necessarily decided; (4) the doctrine is asserted against a party to the former action or one who was in privity with such a party; and (5) the former decision is final and was made on the merits.' [Citation.]" (McCutchen v. City of Montclair (1999) 73 Cal.App.4th 1138, 1144, 87 Cal.Rptr.2d 95, emphasis added; see also Old Republic Ins. Co. v. Superior Court (1998) 66 Cal. App.4th 128, 151, 77 Cal.Rptr.2d 642; Lyons v. Security Pacific Nat. Bank (1995) 40 Cal.App.4th 1001, 1015, 48 Cal. Rptr.2d 174.) "The party asserting collateral estoppel bears the burden of establishing these requirements." (Lucido v. Superior Court (1990) 51 Cal.3d 335, 341, 272 Cal.Rptr. 767, 795 P.2d 1223; Townsel v. San Diego Metropolitan Transit Development Bd. (1998) 65 Cal.App.4th 940, 951, 77 Cal.Rptr.2d 231.) Even if these threshold requirements are established, res judicata will not be applied "if injustice would result or if the public interest requires that relitigation not be foreclosed." (Consumers Lobby Against Monopolies v. Public Utilities Com. (1979) 25 Cal.3d 891, 902, 160 Cal.Rptr. 124, 603 P.2d 41.)
Having before us a prior final judgment on the merits in an action between the same parties, we focus on the identity-of-issues requirement to resolve respondent's claim of res judicata. Unless the issue or cause of action in the two actions is identical, the first judgment does not stand as a bar to the second suit. (Agarwal v. Johnson (1979) 25 Cal.3d 932, 954, 160 Cal. Rptr. 141, 603 P.2d 58; Vary v. Forrest (1988) 201 Cal.App.3d 1506, 1511, 247 Cal. Rptr. 873; Winn v. Board of Pension Commissioners (1983) 149 Cal.App.3d 532, 537, 197 Cal.Rptr. 111.) "`If "anything is left to conjecture as to what was necessarily involved and decided" there can be no collateral estoppel [citations].... "[I]t must appear ... that the precise question was raised and determined in the former suit...."' [Citation.]" (Southwell v. Mallery, Stern & Warford (1987) 194 Cal. App.3d 140, 144, 239 Cal.Rptr. 371.)
To define a cause of action, California follows the primary right theory, which conceives of a cause of action as "`... 1) a primary right possessed by the plaintiff, 2) a corresponding primary duty devolving upon the defendant, and 3) a delict or wrong done by the defendant which consists in a breach of such primary right and duty. [Citation.] Thus, two actions constitute a single cause of action if they both affect the same primary right.... [Citation.]' [Citation.]" (Acuna v. Regents of University of California (1997) 56 Cal.App.4th 639, 648, 65 Cal. Rptr.2d 388.) "[T]here is only a single cause of action for the invasion of one primary right," even if multiple theories of recovery are asserted. (Agarwal v. Johnson, supra, 25 Cal.3d at p. 954, 160 Cal. Rptr. 141, 603 P.2d 58; see also Zimmerman v. Stotter (1984) 160 Cal.App.3d 1067, 1073, 207 Cal.Rptr. 108.) We must compare the two actions, looking at the rights which are sought to be vindicated and the harm for which redress is claimed. (Zimmerman v. Stotter, supra, at p. 1073, 207 Cal.Rptr. 108; City of Los Angeles v. Superior Court (1978) 85 Cal.App.3d 143, 153, 149 Cal.Rptr. 320.) "Reference must be made to the pleadings and proof in each case." (Wimsatt v. Beverly Hills Weight etc. Internal, Inc. (1995) 32 Cal.App.4th 1511, 1517, 38 Cal.Rptr.2d 612.)
The present action for breach of written contract does not assert the same primary right as appellant's prior action in *51 family law court to establish paternity. Appellant previously sought to establish that he was the legal father of the child, with the attendant rights of custody and visitation. The trial court found that he lacked standing to bring the paternity action. Resolution of the enforceability of the contract was unnecessary to the court's judgment in the family law dispute. (In re Marriage of Rabkin (1986) 179 Cal. App.3d 1071, 1082-1083, 225 Cal.Rptr. 219.) Here, the question of jurisdiction or standing is not before us. Appellant has sued respondent for damages for her failure to abide by the written contract between them, not for any rights to the child. Neither the issue of his standing to request paternity nor his paternity rights must necessarily be adjudicated to resolve appellant's claim for damages for respondent's breach of contract. Thus, the prior judgment does not bar the current action. (County of Santa Clara v. Deputy Sheriffs' Assn. (1992) 3 Cal.4th 873, 879, fn. 7, 13 Cal.Rptr.2d 53, 838 P.2d 781; Toumsel v. San Diego Metropolitan Transit Development Bd., supra, 65 Cal.App.4th at pp. 951-952, 77 Cal.Rptr.2d 231; Wimsatt v. Beverly Hills Weight etc. Internal, Inc., supra, 32 Cal.App.4th at p. 1524, 38 Cal. Rptr.2d 612.)[5]

II. The Validity of the Agreement.
Proceeding to the merits of the appeal, we must first assess the validity and enforceability of the agreement. Appellant maintains that contracts between domestic partners for custody and support of children are binding between the parties, at least to the extent of an action for damages. Respondent argues that agreements between a parent and a "non-parent" such as appellant are "illegal and unenforceable because they are in an area entirely preempted by statutory mechanisms for creating or establishing parenthood."
Generally courts will not assist in enforcing an agreement when the object of the agreement is either illegal or against public policy. (Birbrower, Montalbano, Condon & Frank v. Superior Court (1998) 17 Cal.4th 119, 138, 70 Cal.Rptr.2d 304, 949 P.2d 1.) This rule is applied not to secure justice between the parties but to promote a societal recognition that certain types of transactions should be discouraged. (Moran v. Harris (1982) 131 Cal.App.3d 913, 918, 182 Cal.Rptr. 519.) "A contract may be illegal or in contravention of public policy either in its apparent substance and purpose [citation] or in the consideration upon which it is based [citations]." (Kallen v. Delug (1984) 157 Cal. App.3d 940, 949, 203 Cal.Rptr. 879.)
"`A promise or other term of an agreement is unenforceable on grounds of public policy if legislation provides that it is unenforceable or the interest in its enforcement is clearly outweighed in the circumstances by a public policy against the enforcement of such terms'" (Bovard v. American Horse Enterprises, Inc. (1988) 201 Cal.App.3d 832, 840, 247 Cal. Rptr. 340, quoting from Rest.2d Contracts, § 178(1).) "Whether a contract is illegal or contrary to public policy is a question of law to be determined from the circumstances of each particular case." (Jackson v. Rogers & Wells (1989) 210 Cal.App.3d 336, 349-350, 258 Cal.Rptr. 454.) "Before labeling a contract as being contrary to public policy, courts must carefully inquire into the nature of the conduct, the extent of public harm which may be involved, and the moral quality of the conduct of the parties in light of the prevailing standards of the community." (Moran v. Harris, supra, 131 Cal.App.3d at p. 920, 182 Cal. Rptr. 519.)
"The question whether a contract violates public policy necessarily involves a degree of subjectivity. Therefore, `... courts have been cautious in blithely applying public policy reasons *52 to nullify otherwise enforceable contracts. This concern has been graphically articulated by the California Supreme Court as follows: "It has been well said that public policy is an unruly horse, astride of which you are carried into unknown and uncertain paths, ... While contracts opposed to morality or law should not be allowed to show themselves in courts of justice, yet public policy requires and encourages the making of contracts by competent parties upon all valid and lawful considerations, and courts so recognizing have allowed parties the widest latitude in this regard; and, unless it is entirely plain that a contract is violative of sound public policy, a court will never so declare. `The power of the courts to declare a contract void for being in contravention of sound public policy is a very delicate and undefined power, and, like the power to declare a statute unconstitutional, should be exercised only in cases free from doubt.' [Citation.] ... `No court ought to refuse its aid to enforce a contract on doubtful and uncertain grounds. The burden is on the defendant to show that its enforcement would be in violation of the settled public policy of this state, or injurious to the morals of its people.' [Citation.]"` [Citations.]" (Bovard v. American Horse Enterprises, Inc., supra, 201 Cal.App.3d at pp. 838-839, 247 Cal.Rptr. 340.)
Thus, despite the res judicata effect of the prior judgment, we cannot turn a blind eye to appellant's status and rights with regard to the child to properly assess the public policy considerations surrounding his agreement with respondent. We commence our inquiry with recognition that appellant does not qualify as either a "presumed" or "natural" father of the child under the UPA, which governs California law. (Nancy S. v. Michele G. (1991) 228 Cal.App.3d 831, 836, 279 Cal.Rptr. 212.) "`The UPA provides a comprehensive scheme for judicial determination of paternity, and was intended to rationalize procedure, to eliminate constitutional infirmities in then existing state law, and to improve state systems of support enforcement.' [Citations.]" (Adoption of Michael H. (1995) 10 Cal.4th 1043, 1050, 43 Cal. Rptr.2d 445, 898 P.2d 891.) "Under the UPA, the `parent and child relationship' is defined as `the legal relationship existing between a child and the child's natural or adoptive parents.... The term includes the mother and child relationship and the father and child relationship.' [Citation.]" (Barkaloff v. Woodward (1996) 47 Cal. App.4th 393, 399, 55 Cal.Rptr.2d 167.) The term "parent" in the UPA was "intended to refer to a person upon whom that status has been legally conferred that is, a natural or adoptive parent." (In re Jodi B. (1991) 227 Cal.App.3d 1322, 1328, 278 Cal.Rptr. 242.) The definition of parent encompasses "`... the natural mother and father of a child born of their marriage, an adoptive father or mother, a natural mother of an illegitimate child, and, under some circumstances, a father of an illegitimate child if the status of father has been judicially conferred upon him.' [Citation.]" (In re Sarah C. (1992) 8 Cal. App.4th 964, 972, 11 Cal.Rptr.2d 414.)
"In essence, therefore, our statutory scheme creates three classes of parents: mothers, fathers who are presumed fathers, and fathers who are not presumed fathers." (Adoption of Michael H., supra, 10 Cal.4th at p. 1051, 43 Cal.Rptr.2d 445, 898 P.2d 891.) Appellant is not the biological father of the child nor did he adopt her. The concept of "`legally conferred' status" of a father is set forth in section 7611, "which provides when a man will be regarded as a child's `presumed father.'" (In re Sarah G, supra, 8 Cal.App.4th at p. 972, 11 Cal.Rptr.2d 414.) Under section 7611, subdivision (d) "a man who has neither legally married nor attempted to legally marry the mother of his child cannot become a presumed father unless he both `receives the child into his home and openly holds out the child as his natural child.' [Citation.]" (Adoption of Michael H., supra, at p. 1051, 43 Cal.Rptr.2d 445, 898 P.2d 891; see also Miller v. Miller (1998) 64 Cal.App.4th 111, 117, 74 Cal.Rptr.2d *53 797; In re Tanis H. (1997) 59 Cal.App.4th 1218, 1228, 69 Cal.Rptr.2d 380; In re Spencer W. (1996) 48 Cal.App.4th 1647, 1652, 56 Cal.Rptr.2d 524.)[6]
The law thus "permits the adoption of illegitimate children by single persons...." (Lavell v. Adoption Institute (1960) 185 Cal.App.2d 557, 560-561, 8 Cal. Rptr. 367.) "Under this statutory provision, the natural father of an illegitimate child may legitimate his offspring by publicly acknowledging the child as his own, receiving it into his family (with the consent of his wife if he is married), and otherwise treating it as if it were legitimate." (In re Richard M. (1975) 14 Cal.3d 783, 792-793, 122 Cal.Rptr. 531, 537 P.2d 363.) The statute provides "for the adoption by the father of an otherwise illegitimate child. `The father of an illegitimate child, by publicly acknowledging it as his own, receiving it as such, with the consent of his wife, if he is married, into his family, and otherwise treating it as if it were a legitimate child, thereby adopts it as such; and such child is thereupon deemed for all purposes legitimate from the time of its birth(Rodriguez v. Rodriguez (N.D.Cal.1971) 329 F.Supp. 597, 599, quoting Civ.Code, former § 230.)
While appellant has alleged in his complaint the elements of reception of the child into his home and open acknowledgement of her as his daughter, he nevertheless cannot become a "presumed father" under section 7611, subdivision (d), absent any "biological link" to her. (In re Baby Girl M. (1984) 37 Cal.3d 65, 74, 207 Cal. Rptr. 309, 688 P.2d 918.) One of the essential elements of the statute is "paternity" of the child. (In re Richard M., supra, 14 Cal.3d at p. 793, 122 Cal.Rptr. 531, 537 P.2d 363.) Section 7611, subdivision (d) is designed "to serve the function of settling questions of biological parenthood." (In re Marriage of Moschetta (1994) 25 Cal. App.4th 1218, 1226, 30 Cal.Rptr.2d 893.) Without any biological, natural, or genetic connection with the child, the statutory presumption of paternity is unavailable to appellant. (Ibid.)
Where, as in the case before us, the child has been conceived through "heterologous artificial insemination,"[7] and the donor is anonymous, indeed the child "does not have a `natural father,' as that term is commonly used." (People v. Sorensen, supra *54 68 Cal.2d at p. 284, 66 Cal.Rptr. 7, 437 P.2d 495.) In that situation, the term "father" "cannot be limited to the biologic or natural father as those terms are generally understood. The determinative factor is whether the legal relationship of father and child exists." (Ibid.) "Since there is no `natural father,' we can only look for a lawful father." (Ibid., italics added.)
Thus, in People v. Sorensen, supra, 68 Cal.2d 280, 66 Cal.Rptr. 7, 437 P.2d 495, our Supreme Court held that a man may be found criminally liable for failing to pay for the support of a child born to his wife during the marriage as a result of artificial insemination using sperm from an anonymous donor. The high court emphasized the role of the husband in causing the birth, even though he had no biological connection to the child: "[A] reasonable man who ... actively participates and consents to his wife's artificial insemination in the hope that a child will be produced whom they will treat as their own, knows that such behavior carries with it the legal responsibilities of fatherhood and criminal responsibility for nonsupport. One who consents to the production of a child cannot create a temporary relation to be assumed and disclaimed at will, but the arrangement must be of such character as to impose an obligation of supporting those for whose existence he is directly responsible." (68 Cal.2d at p. 285, 66 Cal.Rptr. 7, 437 P.2d 495.) The court added that the husband was "directly responsible" for the "existence" of the child and without his "active participation and consent the child would not have been procreated." (Ibid.)
"The Sorensen definition of `father' in a criminal proceeding is supported by a multitude of civil cases. In Louis v. Louis, 7 Cal.App.3d 851, 853 [86 Cal.Rptr. 834], the court said: `The husband is the legal father even though biologically the fact may be otherwise. [Citations.]'" (People v. Thompson (1979) 89 Cal.App.3d 193, 201, 152 Cal.Rptr. 478.)[8]
Section 7613 provides specific statutory support for the proposition that a husband may be deemed a father under the UPA in the case of artificial insemination of his wife. (In re Marriage of Buzzanca, supra, 61 Cal.App.4th at p. 1417, 72 Cal. Rptr.2d 280; Sherwyn v. Department of Social Services (1985) 173 Cal.App.3d 52, 56, 218 Cal.Rptr. 778.) In the words of the statute: "If, under the supervision of a licensed physician and surgeon and with the consent of her husband, a wife is inseminated artificially with semen donated by a man not her husband, the husband is treated in law as if he were the natural *55 father of a child thereby conceived." (§ 7613, subd. (a).) Under subdivision (b) of section 7613, the donor of the semen is "treated in law as if he were not the natural father of a child thereby conceived." [9] "[T]he husband's written consent is sufficient to establish legal paternity under section 7613, subdivision (a)." (Alexandria S. v. Pacific Fertility Medical Center, Inc. (1997) 55 Cal.App.4th 110,126, 64 Cal.Rptr.2d 23.) "Indeed, the establishment of fatherhood and the consequent duty to support when a husband consents to the artificial insemination of his wife is one of the well-established rules in family law." (In re Marriage of Buzzanca, supra, at p. 1418, 72 Cal.Rptr.2d 280, fn. omitted.) Legal paternity under the statute is established with written consent. (Alexandria S. v. Pacific Fertility Medical Center, Inc., supra, at pp. 124, 126, 64 Cal.Rptr.2d 23.)
Appellant, however, was not respondent's husband, and so does not fall precisely within the scope and protections of section 7613. (See Jhordan C. v. Mary K, supra, 179 Cal.App.3d at p. 395, 224 Cal. Rptr. 530.) Nevertheless, we are persuaded that his status has the elements of those of a lawful father under the decision in Sorensen by virtue of his written consent to the artificial insemination of respondent and voluntary consequent assumption of fatherhood duties. (See In re Marriage of Buzzanca, supra, 61 Cal. App.4th at p. 1421, 72 Cal.Rptr.2d 280; Alexandria S. v. Pacific Fertility Medical Center, Inc., supra, 55 Cal.App.4th at p. 125, fn. 4, 64 Cal.Rptr.2d 23.) Indeed, the UPA expresses a legislative preference for the extension of parent and child relationship equally to married and unmarried parties. The UPA was enacted "to eliminate the legal distinction between legitimate and illegitimate children." (Johnson v. Calvert (1993) 5 Cal.4th 84, 88, 19 Cal. Rptr.2d 494, 851 P.2d 776; People v. Vega, supra, 33 Cal.App.4th at p. 710, 39 Cal. Rptr.2d 479.) It "was plainly intended to establish and promote the rights of putative fathers, and to remove obstacles to the maintenance of parental relations for the benefit of `illegitimate' children." (People v. Johnson (1984) 151 Cal.App.3d 1021, 1025, 199 Cal.Rptr. 231.) According to section 7602: "The parent and child relationship extends equally to every child and to every parent, regardless of the marital status of the parents." The law "contemplates the establishment of lawful fatherhood in a situation where an intended father has no biological relationship to a child who is procreated as a result of the father's (as well as the mother's) consent to a medical procedure." (In re Marriage of Buzzanca, supra, at p. 1421, 72 Cal. Rptr.2d 280, first italics added.)
We are also cognizant of the principle that "Parents have a right to contract with each other as to the custody and control of their offspring, and to stipulate away their respective parental rights. Such contracts are binding upon them." (Stewart v. Stewart (1955) 130 Cal.App.2d 186, 193, 278 P.2d 441; see also Denham v. Martina (1963) 214 Cal.App.2d 312, 319, 29 Cal.Rptr. 377.) Of course, "inasmuch as the children's welfare is the factor of paramount concern, the children are not bound by the contract, and the law vests in the court power to provide for the custody and control of minor children. No such contract may, insofar as the children are concerned, abridge the power of the court in appropriate proceedings to provide for the support of the children by their parents or for their custody." (Puckett v. Puckett (1943) 21 Cal.2d 833, 839, 136 P.2d 1; see also Armstrong v. Armstrong (1976) 15 Cal.3d 942, 947, 126 Cal.Rptr. 805, 544 P.2d 941; In re Marriage of Goodarzirad (1986) 185 Cal.App.3d 1020, 1026-1027, 230 Cal.Rptr. 203.) "[S]uch contracts, while *56 not void or illegal, are not binding on a court...." (Adoption of Matthew B. (1991) 232 Cal.App.3d 1239, 1259, 284 Cal. Rptr. 18.) "But as between the parents, themselves, a promise by one parent that the other may have the custody and control of their child is legal and is a sufficient consideration to support an agreement on the part of the parent in whose favor the promise is made." (Tiffany & Co. v. Spreckels (1927) 202 Cal. 778, 791, 262 P. 742; see also Puckett v. Puckett, supra, at pp. 839-840, 136 P.2d 1; Potts v. Superior Court (1964) 229 Cal.App.2d 692, 694, 40 Cal.Rptr. 521; Brown v. Brown (1951) 104 Cal.App.2d 88, 92, 230 P.2d 651; Millard v. Millard (1951) 102 Cal.App.2d 249, 253, 227 P.2d 477.) Only those "`[a]greements and stipulations compromising the parents' statutory child support obligation or purporting to divest the family court of jurisdiction over child support orders are void as against public policy. [Citations.]' [Citation.]" (In re Marriage of Lusby (1998) 64 Cal.App.4th 459, 469, 75 Cal.Rptr.2d 263.)
We discern nothing in the agreement between appellant and respondent that so offends public policy as to require us to find it illegal or invalid. To the contrary, recognizing the validity of appellant's contractual promise to "care for and support and educate" the child as though it was his "natural child" serves rather than contravenes the compelling public policies of family law to legitimate children, provide for their support, foster the best interests of the child, and promote familial responsibility. (In re Marriage of Buzzanca, supra, 61 Cal.App.4th at p. 1418, 72 Cal.Rptr.2d 280; In re Marriage of Ryan (1994) 22 Cal.App.4th 841, 848, 27 Cal. Rptr.2d 580.) Much like the surrogacy contract at issue in Johnson v. Calvert, supra, 5 Cal.4th at pages 95-97, 19 Cal. Rptr.2d 494, 851 P.2d 776, the agreement between appellant and respondent is not inconsistent with public policy, and serves as a proper expression of the intent of the parties from which to ascertain their rights and obligations, particularly where paternity is not denied or remains ambiguous under the law.[10] (See also In re Marriage of Moschetta, supra, 25 Cal.App.4th at p. 1231, 30 Cal.Rptr.2d 893; McIntyre v. Crouch (1989) 98 Or.App. 462, 780 P.2d 239, 244-245; In Interest of R.C. (Colo. 1989) 775 P.2d 27, 34-35, in which an artificial insemination agreement between an "unmarried recipient" and a "known donor" to treat the latter as the father of the conceived child, and the subsequent conduct of the donor, were found "relevant to preserving the donor's parental rights" despite a statutesimilar to section 7613precluding the assertion of parental rights and obligations by donors; CM. v. C.C. (1977) 152 N.J.Super. 160, 167-168 *57 [377 A.2d 821, 825], where the court concluded that the semen donor's "consent and active participation" in the artificial insemination procedure evinced an intent "to assume the responsibilities of parenthood.")
Thus, while the agreement at issue here cannot grant parental rights to appellant that the law otherwise expressly denies to him, infringe upon the authority of the court to provide for the appropriate custody and support of the child, or abridge the rights of the child, as between appellant and respondent it is binding. (In re Ruby T. (1986) 181 Cal.App.3d 1201, 1204, 227 Cal.Rptr. 8; Potts v. Superior Court, supra, 229 Cal.App.2d at p. 694, 40 Cal.Rptr. 521.) The recognized power of the court to act to protect the best interests of the child does not relieve respondent of the obligations into which she has entered with appellant. (Potts v. Superior Court, supra, at p. 694, 40 Cal.Rptr. 521.) This is particularly so, in our view, where appellant stands in a position at least tantamount to a lawful father in an artificial insemination case, who, although without biological relationship to the child, has given permission along with the mother for procreation of the child, and voluntarily assumed and exercised the responsibilities of fatherhood. (See People v. Sorensen, supra, 68 Cal.2d at p. 285, 66 Cal.Rptr. 7, 437 P.2d 495; In re Marriage of Buzzanca, supra, 61 Cal.App.4th at p. 1418, 72 Cal.Rptr.2d 280.) His paternity status under the circumstances is neither directly prohibited by legislation nor, we conclude, does it infringe upon the prevailing standards of the community.
Finally, we consider the nature and effect of respondent's conduct, in assessing the validity of the agreement. In addition to her express promise to honor appellant's parental rights and to assert no "contrary position" in any legal proceeding, respondent had the benefit of appellant's contractual obligation to care for and support the child. Under principles of equitable estoppel, we cannot now countenance her repudiation of appellant's rights under the agreement. (In re Marriage of Buzzanca, supra, 61 Cal.App.4th at p. 1420, 72 Cal.Rptr.2d 280.) We would rule no differently if the roles were reversed and appellant was the party now seeking to renounce his contractual obligations to support the child. (People v. Sorensen, supra, 68 Cal.2d at p. 285, 66 Cal.Rptr. 7, 437 P.2d 495; Clevenger v. Clevenger (1961) 189 Cal.App.2d 658, 662, 11 Cal. Rptr. 707; Karin T. v. Michael T. (1985) 484 N.Y.S.2d 780, 782-783 [127 Misc.2d 14].[11]) After expressly accepting appellant's status as lawful father, conceiving the child with the intention that appellant would act as her father, and accepting his *58 financial assistance with the support of the child, respondent must be precluded from "turning around and disclaiming any responsibility" under the agreement. (In re Marriage of Buzzanca, supra, at p. 1420, 72 Cal.Rptr.2d 280; see also Adoption of Matthew B., supra, 232 Cal.App.3d at p. 1273, 284 Cal.Rptr. 18.) "One who consents to the production of a child cannot create a temporary relation to be assumed and disclaimed at will...." (People v. Sorensen, supra, at p. 285, 66 Cal.Rptr. 7, 437 P.2d 495.) As our high court long ago observed when discussing the binding effect of child custody and support agreements: "To hold that one competent to contract, who, upon a subject matter good in law, and for a sufficient consideration, enters into written stipulations and covenants of the most solemn character with another, should, the next moment, without pretense of fraud, mistake, or undue influence, or other cause than a mere change of mind, be permitted to absolutely withdraw from, and set at naught, such obligations, without regard to the desire of the other contracting party, would, to say the least, be a strong departure in the law of contracts." (Sargent v. Sargent (1895) 106 Cal. 541, 545, 39 P. 931.)
Respondent seeks to deny enforcement of the agreement by reliance on cases that have denied custody or visitation rights to a "lesbian partner who is not a biological or adoptive parent" of a child conceived by artificial insemination. (See Guardianship of Z.C.W. (1999) 71 Cal.App.4th 524, 527, 84 Cal.Rptr.2d 48; West v. Superior Court (1997) 59 Cal.App.4th 302, 309, 69 Cal. Rptr.2d 160; Nancy S. v. Michele G., supra, 228 Cal.App.3d at p. 841, 279 Cal. Rptr. 212; Curiale v. Reagan (1990) 222 Cal.App.3d 1597, 1600-1601, 272 Cal.Rptr. 520.) The courts have refused to recognize or expand the doctrines of "de facto parenthood," equitable estoppel, in loco parentis, guardianship, or the contractual right to parenthood, to grant custody rights to a nonparent who was otherwise excluded by law from paternity rights. (See also In re Marriage of Lewis & Goetz (1988) 203 Cal.App.3d 514, 519-520, 250 Cal.Rptr. 30, in which the court rejected theories of "equitable parent" or "equitable adoption" to deny a stepparent joint custody on dissolution.) But we are not deciding custody or visitation rights in this appeal.[12] In contrast to the cases cited by respondent, appellant's action is for breach of a written agreement, and seeks damages, not custody of the child.[13] We therefore conclude that the agreement upon which appellant's breach of contract action for damages is based is not in its entirety illegal or unenforceable.

III. The Remedies Available to Appellant.
We next focus upon the remedies available to appellant. Respondent maintains that appellant's allegations of intrusion upon his right to develop "an intimate relationship with a child" have been "disallowed on public policy grounds" in California. Appellant insists that he is entitled to compensation under the contract for deprivation of the "companionship" of the child, or at least must be permitted to amend the complaint to allege causes of action for intentional infliction of emotional distress and unjust enrichment. We define the issue as whether, even if the contract is not illegal or invalid, appellant is entitled to the damages he seeks for the loss of his relationship with the child.
Appellant's claim in his breach of contract action of "enduring mental and emotional suffering and distress from the loss of the relationship, custody, visitation, and parental rights as to the minor child" immediately runs afoul of the rule that *59 "damages for mental suffering and emotional distress are generally not compensable in contract actions." (Applied Equipment Corp. v. Litton Saudi Arabia. Ltd. (1994) 7 Cal.4th 503, 516, 28 Cal.Rptr.2d 475, 869 P.2d 454; see also Cates Construction, Inc. v. Talbot Partners (1999) 21 Cal.4th 28, 4&44, 86 Cal.Rptr.2d 855, 980 P.2d 407.) "`Recovery for emotional disturbance will be excluded unless the breach also caused bodily harm or the contract or the breach is of such a kind that serious emotional disturbance was a particularly likely result.' [Citation.]" (Erlich v. Menezes (1999) 21 Cal.4th 543, 558-559, 87 Cal.Rptr.2d 886, 981 P.2d 978.) An exception is created where the contract "`by its nature put[s] [the defendant] on notice that a breach would result in emotional and mental suffering by [plaintiff]. [Citations.]' [Citation.]" (Selden v. Dinner (1993) 17 Cal.App.4th 166, 172-173, 21 Cal.Rptr.2d 153.) "Cases permitting recovery for emotional distress typically involve mental anguish stemming from more personal undertakings the traumatic results of which were unavoidable," or "contracts in which emotional concerns are the essence of the contract." (Erlich v. Menezes, supra, at p. 559, 87 Cal.Rptr.2d 886, 981 P.2d 978.) While emotional harm to appellant from denial of his parental rights may have been entirely foreseeable, we have doubts that it falls within the exception to the rule barring recovery of damages for emotional distress in contract actions.
In any event, we conclude that recovery of damages by appellant in tort for emotional distress based upon the loss of his relationship with the child is not permitted. "[I]n some instances the courts have concluded that allowing a remedy in tort would be contrary to public policy." (Dale v. Dale (1998) 66 Cal. App.4th 1172, 1184, 78 Cal.Rptr.2d 513.) We are persuaded that the present case is one of those instances, as in Nagy v. Nagy (1989) 210 Cal.App.3d 1262, 258 Cal.Rptr. 787, where the plaintiff "pled causes of action for intentional infliction of emotional distress and fraud" based upon misrepresentations by his former wife that a child born to her during the marriage was fathered by him. (Id., at p. 1267, 258 Cal. Rptr. 787.) The plaintiff alleged that he "developed] a very close and intimate relationship with [the child] and did and performed all acts that a father would towards a son," which caused him mental anguish and emotional distress when he subsequently learned that the child was not his. (Id., at p. 1266, 258 Cal.Rptr. 787.) The court concluded that providing a remedy for the wrong suffered by the plaintiff "would be contrary to public policy. [Citation.] In our opinion, allowing a nonbiological parent to recover damages for developing a close relationship with a child misrepresented to be his and performing parental acts is not a `damage' which should be compensable under the law. Although we do not condone respondent's misrepresentations, they are similar to a `betrayal' for which the law wisely should not provide a remedy." (Id., at pp. 1269-1270, 258 Cal.Rptr. 787.)
Similarly, in Richard P. v. Superior Court (1988) 202 Cal.App.3d 1089, 249 Cal. Rptr. 246, it was alleged that the defendant Richard falsely represented that the plaintiff Gerald was the father of a child born to Gerald's wife, with the intent to deceive the plaintiff and induce him to support the child. (Id., at p. 1092, 249 Cal.Rptr. 246.) In fact, Richard was the natural father of the child. The court found that "any wrong which has occurred as a result of Richard's actions is not one which can be redressed in a tort action. We do not doubt that this lawsuit emanated from an unhappy situation in which the real parties in interest suffered grief. We feel, however, that the innocent children here may suffer significant harm from having their family involved in litigation such as this and that this is exactly the type of lawsuit which, if allowed to proceed, might result in more social damage than will occur if the courts decline to intervene. `We do not believe that the law should *60 provide a basis for such interfamilial warfare.' [Citation.]" (Id., at p. 1094, 249 Cal.Rptr. 246.) [14] The court was also persuaded to deny tort compensation to the plaintiff by the lack of any physical injuries to him and the "potential for harm to the innocent children." (Id., at p. 1095, 249 Cal.Rptr. 246.) The court did not, however, "foreclose the possibility that a man in Gerald's position might be able to recover actual out of pocket costs incurred in supporting another man's children on an equitable theory for reimbursement, such as unjust enrichment." (Id., at p. 1096, fn. 3, 249 Cal.Rptr. 246.)
Here, appellant has alleged breach of a promise to recognize his paternity of the child. "Losses of parental or filial consortium are not actionable. `[T]he inadequacy of monetary damages to make whole the loss suffered, considered in light of the social cost of paying such awards, constitutes a strong reason for refusing to recognize the asserted claim.' [Citations.]" (Foy v. Greenblott (1983) 141 Cal. App.3d 1, 7, 190 Cal.Rptr. 84.) In Borer v. American Airlines, Inc. (1977) 19 Cal.3d 441, 453, 138 Cal.Rptr. 302, 563 P.2d 858, our high court refused to recognize extension of liability to deprivation of the parent-child relationship upon consideration of the strong public policy reasons "which bear on this question, including the inadequacy of monetary compensation to alleviate that tragedy, the difficulty of measuring damages, and the danger of imposing extended and disproportionate liability...." (See also Thing v. La Chusa (1989) 48 Cal.3d 644, 664-665, 257 Cal. Rptr. 865, 771 P.2d 814.) To the extent appellant seeks damages for the loss of his paternity rights, his action implicates an intensely private familial association in which the courts are reluctant to intervene. (Perry v. Atkinson, supra, 195 Cal. App.3d at p. 19, 240 Cal.Rptr. 402.) The court is also poorly equipped to assess and compensate appellant with damages for the emotional harm he suffered due to the loss of his relationship with the child. As the court declared in Nagy v. Nagy, supra, 210 Cal.App.3d at p. 1269, 258 Cal.Rptr. 787: "`To attempt to correct such wrongs or give relief from their effects "may do more social damage than if the law leaves them alone." [Citation.]' [Citation.]" We thus conclude that appellant cannot recover damages under a breach of contract theory for any loss of the bargained-for relationship with the child, and is not entitled to amend his pleading to state a cause of action for infliction of emotional distress.
We nevertheless conclude that appellant is not left entirely without a remedy. The preclusion of his claim for general damages for emotional harm on public policy grounds does not operate to deny him recovery of special damages for readily ascertainable economic loss under an unjust enrichment theory. (See Turpin v. Sortini (1982) 31 Cal.3d 220, 237-239, 182 Cal.Rptr. 337, 643 P.2d 954; Andalon v. *61 Superior Court (1984) 162 Cal.App.3d 600, 612-613, 208 Cal.Rptr. 899; Foy v. Greenblott, supra, 141 Cal.App.3d at p. 14, 190 Cal.Rptr. 84; Call v. Kezirian (1982) 135 Cal.App.3d 189, 194, 185 Cal.Rptr. 103.) "An individual is required to make restitution if he or she is unjustly enriched at the expense of another. [Citations.] A person is enriched if the person receives a benefit at another's expense. [Citation.] Benefit means any type of advantage." (First Nationwide Savings v. Perry (1992) 11 Cal. App.4th 1657, 1662, 15 Cal.Rptr.2d 173.) "The equitable remedy of restitution to avoid `unjust enrichment' has its roots in the common law. `[O]ne person should not be permitted unjustly to enrich himself at the expense of another, but should be required to make restitution of or for property or benefits received, retained, or appropriated, where it is just and equitable that such restitution be made, and where such action involves no violation or frustration of law or opposition to public policy, either directly or indirectly.' [Citation.]" (Gardiner Solder Co. v. SupAlloy Corp., Inc. (1991) 232 Cal.App.3d 1537, 1542, 284 Cal.Rptr. 206.)
We find no great public policy impediment to appellant's recovery of his economic loss under an unjust enrichment theory. A contract unenforceable in its entirety for public policy reasons may still be enforced in part under compelling circumstances where the lawful and unlawful portions of the agreement may be separated. (Birbrower, Montalbano, Condon & Frank v. Superior Court, supra, 17 Cal.4th at p. 138, 70 Cal.Rptr.2d 304, 949 P.2d 1; Keene v. Harling (1964) 61 Cal.2d 318, 320-321, 38 Cal.Rptr. 513, 392 P.2d 273; Davenport & Co. v. Spieker (1988) 197 Cal.App.3d 566, 569, 242 Cal.Rptr. 911.) Even an illegal contract may be enforced to avoid unjust enrichment or unconscionable injury. (Asdourian v. Araj (1985) 38 Cal.3d 276, 292, 211 Cal. Rptr. 703, 696 P.2d 95.) Illegal contracts "will be enforced under certain circumstances, such as when only a part of the consideration given for the contract involves illegality. In other words, notwithstanding an illegal consideration, courts may sever the illegal portion of the contract from the rest of the agreement. [Citation.] `"`When the transaction is of such a nature that the good part of the consideration can be separated from that which is bad, the Courts will make the distinction, for the ... law ... [divides] according to common reason; and having made that void that is against law, lets the rest stand[Citations.] If the court is unable to distinguish between the lawful and unlawful parts of the agreement, `the illegality taints the entire contract, and the entire transaction is illegal and unenforceable.' [Citation.]" (Birbrower, Montalbano, Condon & Frank v. Superior Court, supra, at p. 138, 70 Cal. Rptr.2d 304, 949 P.2d 1.)
While the courts generally will not enforce an illegal contract or one against public policy, "`the rule is not an inflexible one to be applied in its fullest rigor under any and all circumstances,'" and "`[a] wide range of exceptions has been recognized'" to enforce contracts "to `avoid unjust enrichment to a defendant and a disproportionately harsh penalty upon the plaintiff.'" (Asdourian v. Araj, supra, 38 Cal.3d at pp. 291-292, 211 Cal.Rptr. 703, 696 P.2d 95, quoting Southfield v. Barrett (1970) 13 Cal.App.3d 290, 294, 91 Cal.Rptr. 514.) "The effect of illegality on a transaction depends on the facts and equities of the particular case." (Adoption of Matthew B., supra, 232 Cal.App.3d at p. 1256, 284 Cal.Rptr. 18.) In each case, the extent of enforceability and the type of remedy granted depend upon a variety of factors, including the nature of the illegality, the policies to be served by enforcing or denying enforcement of the agreement, and the relative culpability and equities of the parties. (Adoption of Matthew B., supra, at p. 1256, 284 Cal.Rptr. 18; Joe A. Freitas & Sons v. Food Packers etc. & Warehousemen (1985) 164 Cal.App.3d 1210, 1219, 211 Cal.Rptr. 157; Homestead Supplies, Inc. v. Executive Life Ins. Co. (1978) 81 Cal. App.3d 978, 989, 147 Cal.Rptr. 22; South *62 Tahoe Gas Co. v. Hofmann Land Improvement Co. (1972) 25 Cal.App.3d 750, 759, 102 Cal.Rptr. 286.) The "appropriate remedy would depend upon a weighing of these factors." (Adoption of Matthew B., supra, at p. 1257, 284 Cal.Rptr. 18.)
In the present case, it is part of the remedyspecific performance of the contract or damages for emotional harm rather than the object or consideration of the agreement that is unenforceable on public policy grounds. An award of compensation to appellant for his economic loss does not contravene those public policy considerations. The public cannot be protected by refusing limited enforcement of the agreement to the extent of unjust enrichment. Appellant will neither obtain custody of the child in contravention of the law, nor be improperly compensated for the loss of his relationship with her. (Cf., Nagy v. Nagy, supra, 210 Cal.App.3d at pp. 1269-1270, 258 Cal.Rptr. 787.) Further, to grant him reimbursement for any amounts he may have expended in performance of the agreement does not now intrude adversely upon private familial matters, and is easily severable from the emotional harm he must be denied on public policy grounds. Custody of the child is no longer at issue, and the social harm to the family, long since disintegrated, from the litigation confined to an unjust enrichment action will not be so egregious as to outweigh appellant's right to at least a partial remedy. Nor does an award of unjust enrichment involve the court in compensation that evades proper assessment. An award limited to unjust enrichment is a relatively mechanical and undemanding calculation. (Turpin v. Sortini, supra, 31 Cal.3d at p. 238, 182 Cal.Rptr. 337, 643 P.2d 954.) "`While the law cannot remove the heartache or undo the harm, it can afford some reasonable measure of compensation towards alleviating the financial burdens.'" (Id., at p. 239, 182 Cal.Rptr. 337, 643 P.2d 954 quoting Gleitman v. Cosgrove (1967) 49 N.J. 22, 227 A.2d 689, 703.)
Although requiring respondent to disgorge any monetary benefit she received at appellant's expense under the agreement may indirectly compromise the funds presently available to her for support, we think the equities of the case and public policy considerations still fall in appellant's favor. According to the complaint, it is respondent who entered into a contract which obligated appellant to support and care for the child and then, in breach of her promise, denied his rights under the contract when it suited her to do so. Respondent will be unjustly enriched at appellant's expense if a remedy is entirely denied to him. In contrast, at least according to the complaint, appellant relied on the agreement and representations by Pacific Fertility that his legal rights were protected. He then performed his obligations pursuant to the agreement until prevented from doing so by respondent. We therefore conclude that the trial court erred in sustaining the demurrer since the complaint states facts disclosing some right to relief. (Longshore v. County of Ventura (1979) 25 Cal.3d 14, 22, 157 Cal. Rptr. 706, 598 P.2d 866.)[15]
We add that the measure of damages to which appellant is entitled for unjust enrichment "is synonymous with restitution." *63 (Dinosaur Development, Inc. v. White, supra, 216 Cal.App.3d at p. 1314, 265 Cal.Rptr. 525.) Restitution is defined "as restoration of the status quo by the awarding of an `amount which would put plaintiff in as good a position as he would have been if no contract had been made and restores to plaintiff value of what he parted with in performing the contract.'" (People v. Martinson (1986) 188 Cal. App.3d 894, 900, 233 Cal.Rptr. 617, citation omitted.) "In modern legal usage, its meaning has frequently been extended to include not only the restoration or giving back of something to its rightful owner, but also compensation, reimbursement, indemnification, or reparation for benefits derived from, or for loss or injury caused to, another." (Dinosaur Development, Inc. v. White, supra, at p. 1315, 265 Cal. Rptr. 525.) "`Ordinarily the benefit to the one and the loss to the other are coextensive, and the result ... is to compel the one to surrender the benefit which he has received and thereby to make restitution to the other for the loss which he has suffered.' (Rest., Restitution, § 1, com. d, p. 13; see also 1 Witkin, Summary of Cal. Law (9th ed. 1987) Contracts, § 95, p. 125.)" (Unilogic, Inc. v. Burroughs Corp. (1992) 10 Cal.App.4th 612, 627, 12 Cal. Rptr.2d 741.) Equitable considerations govern the award of unjust enrichment, however. (First Nationwide Savings v. Perry, supra, 11 Cal.App.4th at p. 1663, 15 Cal.Rptr.2d 173.) Thus, a "party seeking restitution `must generally return any benefit' that it has received. (Rest.2d, Contracts, § 376, com.a, § 384, com.a.)" (California Federal Bank v. Matreyek (1992) 8 Cal.App.4th 125, 134, 10 Cal.Rptr.2d 58.) Respondent may therefore be entitled to an offset to the extent her conduct has conferred an incidental benefit on the economic interest of appellant "that was harmed," but not for the benefit appellant received from his relationship with the child. (Turpin v. Sortini supra, 31 Cal.3d at p. 239, 182 Cal.Rptr. 337, 643 P.2d 954; see also Stills v. Gratton (1976) 55 Cal. App.3d 698, 709, 127 Cal.Rptr. 652.)
Accordingly, the judgment is reversed and the case is remanded to the trial court for proceedings consistent with the views expressed herein. Costs on appeal are awarded to appellant.
STRANKMAN, P.J., and STEIN, J., concur.
NOTES
[1]  The birth certificate was not part of the record on appeal, but was attached to the complaint as an exhibit, and we have augmented the record with it. (Cal. Rules of Court, rule 12(a).)
[2]  Appellant's declaratory relief action was resolved first.
[3]  All further statutory references are to the Family Code unless otherwise indicated.
[4]  In reviewing the order sustaining the demurrer, we consider the prior complaint and judgment, which was judicially noticed in the trial court and is part of the record on appeal. To determine whether to sustain a demurrer on res judicata grounds, judicial notice may be taken of a prior judgment and other court records. (Kirkpatrick v. City of Oceanside (1991) 232 Cal.App.3d 267, 281, 283 Cal.Rptr. 191; Carroll v. Puritan Leasing Co. (1978) 77 Cal.App.3d 481, 486, 143 Cal.Rptr. 772.) We observe that the trial court did not confront the issue of res judicata in sustaining respondent's demurrer.
[5]  We are also persuaded that the important public policy considerations implicated by appellant's present suit militate in favor of resolving the issues presented.
[6]  Subdivision (d) of section 7611, reads: "A man is presumed to be the natural father of a child if ... [¶] (d) He receives the child into his home and openly holds out the child as his natural child." "In defining the rights of unmarried fathers, the Act distinguishes between a presumed father, as determined by the statutory presumptions, and one who is merely a biological father. [Citations.] The unmarried father is treated differently under the Act in custody, support and adoption proceedings depending on his defined status. [Citations.] The presumed father, one who has entered into some familial relationship with the mother and child, is accorded more rights and privileges than the purely biological father." (People v. Vega (1995) 33 Cal. App.4th 706, 710, 39 Cal.Rptr.2d 479.) As explained in Adoption of Michael H., supra, 10 Cal.4th at pp. 1050-1051, 43 Cal.Rptr.2d 445, 898 P.2d 891: "An unwed father's rights and duties ... substantially depend on whether he is a `presumed father' within the meaning of section 7611. ([Adoption of Kelsey S. (1992) ] 1 Cal.4th 816, 823 [4 Cal.Rptr.2d 615, 823 P.2d 1216] [`Whether a biological father is a "presumed father" ... is critical to his parental rights in adoption proceedings.']; see also In re Zacharia D. (1993) 6 Cal.4th 435, 448-449 [24 Cal.Rptr.2d 751, 862 P.2d 751] [only `presumed fathers' are entitled to custody and reunification services].)" "The Legislature has distinguished between presumed and natural fathers, according presumed fathers greater rights than natural fathers. [Citation.] A presumed father is entitled to custody, and where adoption is concerned, his consent or the formal termination of his rights for willful failure to communicate is required. [Citations.] A natural father, on the other hand, is neither entitled to custody nor automatically able to withhold consent to an adoption." (In re Shereece B. (1991) 231 Cal. App.3d 613, 622, 282 Cal.Rptr. 430.)
[7]  Artificial insemination is classed as one of two types, with or without using the husband's semen, known respectively as homologous artificial insemination and heterologous artificial insemination. (See People v. Sorensen (1968) 68 Cal.2d 280, 284, fn. 2, 66 Cal. Rptr. 7, 437 P.2d 495.)
[8]  Also, "Sorensen expresses a rule universally in tune with other jurisdictions. `Almost exclusively, courts which have addressed this issue have assigned parental responsibility to the husband based on conduct evidencing his consent to the artificial insemination.' (In re Baby Doe (1987) 291 S.C. 389 [353 S.E.2d 877, 878]; accord, Gursky v. Gursky (1963) 39 Misc.2d 1083 [242 N.Y.S.2d 406, 411-412] [even though child was not technically `legitimate' under New York law at the time, husband's conduct in consenting to the artificial insemination properly invoked application of the doctrine of equitable estoppel requiring him to support the child]; Anonymous v. Anonymous (1964) 41 Misc.2d 886 [246 N.Y.S.2d 835, 836-837] [following Gursky v. K.S. v. G.S. (1981) 182 N.J.Super. 102 [440 A.2d 64, 68] [because husband did not offer clear and convincing evidence that he had withdrawn his consent to artificial insemination procedure, he was bound by initial consent given earlier and accordingly held to be lawful father of the child];In re Marriage of Adams (1988) 174 Ill.App.3d 595 [124 Ill.Dec. 184, 528 N.E.2d 1075, 1087] [affirming child support award where trial court had determined there was `actual consent' to artificial insemination]; K.B. v. N.B. (Tex.Ct.App.1991) 811 S.W.2d 634, 639] [even though husband did not consent in writing to insemination procedure, his full knowledge of the facts and willing participation in the artificial insemination, involvement in child birth classes, speaking of the child as `our baby' and passage of time before repudiation established that he ratified procedure and was therefore liable for child support]; Levin v. Levin (Ind. 1994) 645 N.E.2d 601, 605 [consent of husband to wife's artificial insemination meant obligation to support because child was a `child of the marriage,' the same as if the child had been 
adopted during the marriage].)" (In re Marriage of Buzzanca (1998) 61 Cal.App.4th 1410, at pp. 1418-1419, 72 Cal.Rptr.2d 280, fn. omitted.)
[9]  "Thus, the California Legislature had afforded unmarried as well as married women a statutory vehicle for obtaining semen for artificial insemination without fear that the donor may claim paternity...." (Jhordan C. v. Mary K. (1986) 179 Cal.App.3d 386, 392, 224 Cal.Rptr. 530.)
[10]  In Johnson v. Calvert, supra, 5 Cal.4th 84, 19 Cal.Rptr.2d 494, 851 P.2d 776, a married couple, Mark and Crispina Calvert, executed an agreement with Anna Johnson to have an embryo created by the sperm of Mark and the egg of Crispina implanted in Anna. The child born was by the terms of the contract to be the Calverts' child, and Anna relinquished all parental rights to the child. Relations deteriorated between the parties during the pregnancy and both the Calverts and Anna Johnson filed actions seeking declarations they were the parents of the unborn child.

In considering the competing claims of Crispina and Anna to be the natural mother pursuant to Civil Code former section 7003, subdivision (1) (now Fam.Code § 7610, subd. (a)), the court found that California law recognizes only one natural mother. (Johnson v. Calvert, supra, 5 Cal.4th at p. 92, fn. 9, 19 Cal.Rptr.2d 494, 851 P.2d 776.) Because both women presented acceptable proof of maternity, neither more compelling than the other, the court looked to the writings of several legal commentators and agreed that "`[w]ithin the context of artificial reproductive techniques,' ... `intentions that are voluntarily chosen, deliberate, express and bargained-for ought presumptively to determine legal parenthood.' (Id., at p. 94, 19 Cal.Rptr.2d 494, 851 P.2d 776, quoting Schultz, Reproductive Technology and Intent-Based Parenthood: An Opportunity for Gender Neutrality (1990) Wis. L.Rev. 297, 323, fn. omitted.) The court concluded that in deciding the issue of maternity, it would look to the intentions of the parties as expressed in the surrogacy contract. (Johnson v. Calvert, supra, at p. 95, 19 Cal. Rptr.2d 494, 851 P.2d 776.)
[11]  In Karin T. v. Michael T., supra, p. 781, the respondent was a female who was "unhappy with her feminine identity and attempted to change that identity and to live like a man." Respondent participated in a marriage ceremony with the petitioner Karin T. that was subsequently the subject of an action to declare it "null and void" and they "lived together in the same household and both contributed to the support of the family and to the children" (id. at p. 782) born to Karin T. "by means of artificial insemination." (at p. 781.) Respondent and petitioner signed an agreement whereby respondent indicated "she was the husband" and declared the children "his own legitimate child or children." (Id., at p. 782.) After the birth of the children, the parties separated and respondent sought to disclaim her parental obligations. The court concluded that "certainly the document which was signed by the respondent and by which these children were brought into the world gives rise to a situation which must provide these two children with remedies. To hold otherwise would allow this respondent to completely abrogate her responsibilities for the support of the children involved and would allow her to benefit from her own fraudulent acts which induced their birth no more so than if she were indeed the natural father of these children. Of course, the respondent was free to engage and live in any lifestyle which she felt appropriate. However, by her course of conduct in this case which brought into the world two innocent children she should not be allowed to benefit from those acts to the detriment of these children and of the public generally." (Id., at p. 784.)
[12]  As we have observed, the prior judgment is res judicata on those matters.
[13]  For instance, in West v. Superior Court, supra, 59 Cal.App.4th at page 304, 69 Cal. Rptr.2d 160, the court expressly observed that the breach of contract action based on the agreement between the parties was not at issue.
[14]  The court further observed: "Our conclusion is supported by analogy by several other decisions. (See, e.g., Stephen K. v. Roni L. [(1980)] 105 Cal.App.3d 640, 164 Cal.Rptr. 618 [relief not available to father who became obligated to support an unwanted child after mother falsely represented to him that she was taking birth control pills]; Perry v. Atkinson (1987) 195 Cal.App.3d 14 [240 Cal.Rptr. 402] [woman could not state cause of action for fraud against married man with whom she had had an intimate relationship based on allegations that she terminated her pregnancy by abortion in reliance upon his false misrepresentations that he would impregnate her the following year either through sexual intercourse or artificial insemination]; In re Marriage of Buckley [ (1982) ] 133 Cal.App.3d 927, 184 Cal.Rptr. 290 [plaintiff could not maintain fraud suit against his former wife based upon allegations that she falsely represented to him that her former marriage had been legally terminated, thereby fraudulently inducing him to enter into a void marriage]; Boyd v. Boyd (1964) 228 Cal.App.2d 374 [39 Cal.Rptr. 400] [demurrer sustained to fraud complaint based on allegations that plaintiff lost her Veterans Administration and social security benefits by marrying man who abandoned her two days later and refused to live with her and support her].)" (Richard P. v. Superior Court, supra, 202 Cal.App.3d at p. 1094, 249 Cal.Rptr. 246.)
[15]  We note that appellant need not amend the pleading to seek compensation under an unjust enrichment theory, as those damages are recoverable in his breach of contract action. (See Al-Husry v. Nilsen Farms Mini-Market, Inc. (1994) 25 Cal.App.4th 641, 650-651, 31 Cal.Rptr.2d 28; Dallman Co. v. Southern Heater Co. (1968) 262 Cal.App.2d 582, 588-589, 68 Cal.Rptr. 873; Nelson v. Dangerfield (1954) 125 Cal.App.2d 146, 150, 269 P.2d 953.) "The phrase `Unjust Enrichment' does not describe a theory of recovery, but an effect: the result of a failure to make restitution under circumstances where it is equitable to do so." (Lauriedale Associates, Ltd. v. Wilson (1992) 7 Cal.App.4th 1439, 1448, 9 Cal. Rptr.2d 774.) "`[I]n any event, ... there is no particular form of pleading necessary to invoke the doctrine' of restitution." (Dinosaur Development, Inc. v. White (1989) 216 Cal.App.3d 1310, 1315, 265 Cal.Rptr. 525, citation omitted.)
