# Auto generated from None by pythongen.py version: 0.9.0
# Generation date:
# Schema: synopsis2
#
# id: http://example.org/sample/example1
# description:
# license:

import dataclasses
import sys
import re
from jsonasobj2 import JsonObj, as_dict
from typing import Optional, List, Union, Dict, ClassVar, Any
from dataclasses import dataclass
from linkml_runtime.linkml_model.meta import EnumDefinition, PermissibleValue, PvFormulaOptions

from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int
from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
from rdflib import Namespace, URIRef
from linkml_runtime.utils.curienamespace import CurieNamespace
from linkml_runtime.utils.metamodelcore import Bool

metamodel_version = "1.7.0"

# Overwrite dataclasses _init_fn to add **kwargs in __init__
dataclasses._init_fn = dataclasses_init_fn_with_kwargs

# Namespaces
FOAF = CurieNamespace('foaf', 'http://xmlns.com/foaf/0.1/')
SAMP = CurieNamespace('samp', 'http://example.org/model/')
XSD = CurieNamespace('xsd', 'http://www.w3.org/2001/XMLSchema#')
DEFAULT_ = SAMP


# Types
class String(str):
    type_class_uri = XSD.string
    type_class_curie = "xsd:string"
    type_name = "string"
    type_model_uri = SAMP.String


class Int(int):
    type_class_uri = XSD.integer
    type_class_curie = "xsd:integer"
    type_name = "int"
    type_model_uri = SAMP.Int


class Boolean(Bool):
    type_class_uri = XSD.boolean
    type_class_curie = "xsd:boolean"
    type_name = "boolean"
    type_model_uri = SAMP.Boolean


# Class references
class PersonId(extended_str):
    pass


class FriendlyPersonId(PersonId):
    pass


@dataclass
class Person(YAMLRoot):
    """
    A person, living or dead
    """
    _inherited_slots: ClassVar[List[str]] = []

    class_class_uri: ClassVar[URIRef] = SAMP.Person
    class_class_curie: ClassVar[str] = "samp:Person"
    class_name: ClassVar[str] = "person"
    class_model_uri: ClassVar[URIRef] = SAMP.Person

    id: Union[str, PersonId] = None
    last_name: str = None
    first_name: Optional[Union[str, List[str]]] = empty_list()
    age: Optional[int] = None
    living: Optional[Bool] = None
    knows: Optional[Union[Union[str, PersonId], List[Union[str, PersonId]]]] = empty_list()

    def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
        if self._is_empty(self.id):
            self.MissingRequiredField("id")
        if not isinstance(self.id, PersonId):
            self.id = PersonId(self.id)

        if self._is_empty(self.last_name):
            self.MissingRequiredField("last_name")
        if not isinstance(self.last_name, str):
            self.last_name = str(self.last_name)

        if not isinstance(self.first_name, list):
            self.first_name = [self.first_name] if self.first_name is not None else []
        self.first_name = [v if isinstance(v, str) else str(v) for v in self.first_name]

        if self.age is not None and not isinstance(self.age, int):
            self.age = int(self.age)

        if self.living is not None and not isinstance(self.living, Bool):
            self.living = Bool(self.living)

        if not isinstance(self.knows, list):
            self.knows = [self.knows] if self.knows is not None else []
        self.knows = [v if isinstance(v, PersonId) else PersonId(v) for v in self.knows]

        super().__post_init__(**kwargs)


@dataclass
class FriendlyPerson(Person):
    """
    Any person that knows someone
    """
    _inherited_slots: ClassVar[List[str]] = []

    class_class_uri: ClassVar[URIRef] = SAMP.FriendlyPerson
    class_class_curie: ClassVar[str] = "samp:FriendlyPerson"
    class_name: ClassVar[str] = "friendly_person"
    class_model_uri: ClassVar[URIRef] = SAMP.FriendlyPerson

    id: Union[str, FriendlyPersonId] = None
    last_name: str = None
    knows: Union[Union[str, PersonId], List[Union[str, PersonId]]] = None

    def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
        if self._is_empty(self.id):
            self.MissingRequiredField("id")
        if not isinstance(self.id, FriendlyPersonId):
            self.id = FriendlyPersonId(self.id)

        if self._is_empty(self.knows):
            self.MissingRequiredField("knows")
        if not isinstance(self.knows, list):
            self.knows = [self.knows] if self.knows is not None else []
        self.knows = [v if isinstance(v, PersonId) else PersonId(v) for v in self.knows]

        super().__post_init__(**kwargs)


# Enumerations


# Slots

{
   "_comments": "Auto generated from None by jsonldcontextgen.py version: 0.1.1\n    Generation date:",
   "@context": {
      "foaf": "http://xmlns.com/foaf/0.1/",
      "samp": "http://example.org/model/",
      "xsd": "http://www.w3.org/2001/XMLSchema#",
      "@vocab": "http://example.org/model/",
      "age": {
         "@type": "xsd:integer",
         "@id": "foaf:age"
      },
      "first_name": {
         "@id": "foaf:firstName"
      },
      "id": "@id",
      "knows": {
         "@type": "@id",
         "@id": "foaf:knows"
      },
      "last_name": {
         "@id": "foaf:lastName"
      },
      "living": {
         "@type": "xsd:boolean"
      },
      "@base": "http://example.org/people/"
   }
}

Person(id='42', last_name='smith', first_name=['Joe', 'Bob'], age=43, living=None, knows=[])
{
  "id": "42",
  "last_name": "smith",
  "first_name": [
    "Joe",
    "Bob"
  ],
  "age": 43,
  "@type": "Person",
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/",
    "samp": "http://example.org/model/",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "@vocab": "http://example.org/model/",
    "age": {
      "@type": "xsd:integer",
      "@id": "foaf:age"
    },
    "first_name": {
      "@id": "foaf:firstName"
    },
    "id": "@id",
    "knows": {
      "@type": "@id",
      "@id": "foaf:knows"
    },
    "last_name": {
      "@id": "foaf:lastName"
    },
    "living": {
      "@type": "xsd:boolean"
    },
    "@base": "http://example.org/people/"
  }
}
@prefix : <http://example.org/model/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix samp: <http://example.org/model/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/people/42> a samp:Person ;
    foaf:age 43 ;
    foaf:firstName "Bob",
        "Joe" ;
    foaf:lastName "smith" .


BASE <http://example.org/model/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>


<String> xsd:string

<Int> xsd:integer

<Boolean> xsd:boolean

<FriendlyPerson> CLOSED {
    (  $<FriendlyPerson_tes> (  &<Person_tes> ;
          rdf:type [ <Person> ] ? ;
          foaf:knows @<Person> +
       ) ;
       rdf:type [ <FriendlyPerson> ]
    )
}

<Person>  (
    CLOSED {
       (  $<Person_tes> (  foaf:firstName @<String> * ;
             foaf:lastName @<String> ;
             foaf:age @<Int> ? ;
             <living> @<Boolean> ? ;
             foaf:knows @<Person> *
          ) ;
          rdf:type [ <Person> ]
       )
    } OR @<FriendlyPerson>
)



Conforms
Conforms
