"""
$Id: __init__.py,v 1.2 2005/02/26 17:56:10 sidnei Exp $
"""

from zope.interface import implements
from interfaces import ISimpleSchema
from interfaces import ITwoSchemata
from Products.Archetypes.public import *
from Acquisition import Implicit

PROJECTNAME = 'Fate'

class SimpleSchema(BaseObject, Implicit):

    implements(ISimpleSchema)
    meta_type = portal_type = archetype_name = 'SimpleSchema'
    isPrincipiaFolderish = 0

    schema = Schema((
        StringField('f1',
                    required=False),
        StringField('f2',
                    required=True),
        ))

registerType(SimpleSchema, PROJECTNAME)

class TwoSchemata(BaseObject, Implicit):

    implements(ITwoSchemata)
    meta_type = portal_type = archetype_name = 'TwoSchemata'
    isPrincipiaFolderish = 0

    schema = Schema((
        StringField('f1',
                    required=False),
        StringField('f2',
                    required=True,
                    schemata='second'),
        ))

registerType(TwoSchemata, PROJECTNAME)

class SimpleWithId(BaseObject, Implicit):

    implements(ISimpleSchema)
    meta_type = portal_type = archetype_name = 'SimpleWithId'
    isPrincipiaFolderish = 0

    schema =  Schema((
        BaseSchema['id'],
        StringField('f1',
                    required=False),
        StringField('f2',
                    required=True),
        ))

registerType(SimpleWithId, PROJECTNAME)

class Box(BaseContent):

    meta_type = portal_type = archetype_name = 'Box'
    isPrincipiaFolderish = 0

    schema = BaseSchema + Schema((
        ReferenceField('contents',
                       accessor='getContents',
                       mutator='setContents',
                       relationship='contains',
                       multiValued=True),
        ))

registerType(Box, PROJECTNAME)

class Thing(BaseContent):

    meta_type = portal_type = archetype_name = 'Thing'
    isPrincipiaFolderish = 0

    schema = BaseSchema + Schema((
        ReferenceField('containers',
                       accessor='getContainers',
                       mutator='setContainers',
                       relationship='contained_into',
                       multiValued=True),
        ))

registerType(Thing, PROJECTNAME)

def initialize(context):

    from Products.CMFCore import utils as cmf_utils
    from Products.CMFCore.CMFCorePermissions import AddPortalContent

    listOfTypes = listTypes(PROJECTNAME)
    content_types, constructors, ftis = process_types(listOfTypes, PROJECTNAME)

    # Register Content
    cmf_utils.ContentInit(
        PROJECTNAME + ' Content',
        content_types=content_types,
        permission=AddPortalContent,
        extra_constructors=constructors,
        fti=ftis,
        ).initialize(context)
