## $Id: interfaces.py 7718 2012-02-28 19:34:51Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
from zope.interface import invariant, Invalid
from zope import schema
from waeup.sirp.interfaces import ISIRPObject
from waeup.sirp.interfaces import MessageFactory as _
from waeup.sirp.hostels.vocabularies import (
    bed_letters, blocks, special_handling, StudentSource)

class IHostelsContainer(ISIRPObject):
    """A container for all kind of hostel objects.

    """

class IHostel(ISIRPObject):
    """A base representation of hostels.

    """

    def loggerInfo(ob_class, comment):
        """Adds an INFO message to the log file
        """

    def updateBeds():
        """Fill hostel with beds or update beds.
        """

    hostel_id = schema.TextLine(
        title = _(u'Hostel Id'),
        readonly = True,
        )

    sort_id = schema.Int(
        title = _(u'Sort Id'),
        required = True,
        default = 10,
        )

    hostel_name = schema.TextLine(
        title = _(u'Hostel Name'),
        required = True,
        default = u'Hall 1',
        )

    floors_per_block = schema.Int(
        title = _(u'Floors per Block'),
        required = True,
        default = 1,
        )

    rooms_per_floor = schema.Int(
        title = _(u'Rooms per Floor'),
        required = True,
        default = 2,
        )

    beds_reserved = schema.List(
        title = _(u'Reserved Beds'),
        value_type = schema.TextLine(
            default = u'',
            required = False,
        ),
        required = True,
        readonly = False,
        default = [],
        )

    blocks_for_female = schema.List(
        title = _(u'Blocks for Female Students'),
        value_type = schema.Choice(
            vocabulary = blocks
            ),
        )

    blocks_for_male = schema.List(
        title = _(u'Blocks for Male Students'),
        value_type = schema.Choice(
            vocabulary = blocks
            ),
        )

    beds_for_fresh = schema.List(
        title = _(u'Beds for Fresh Students'),
        value_type = schema.Choice(
            vocabulary = bed_letters
            ),
        )

    beds_for_returning = schema.List(
        title = _(u'Beds for Returning Students'),
        value_type = schema.Choice(
            vocabulary = bed_letters
            ),
        )

    beds_for_final = schema.List(
        title = _(u'Beds for Final Year Students'),
        value_type = schema.Choice(
            vocabulary = bed_letters
            ),
        )

    beds_for_all = schema.List(
        title = _(u'Beds without category'),
        value_type = schema.Choice(
            vocabulary = bed_letters
            ),
        )

    special_handling = schema.Choice(
        title = _(u'Special Handling'),
        vocabulary = special_handling,
        required = True,
        default = u'regular',
        )

    @invariant
    def blocksOverlap(hostel):
        bfe = hostel.blocks_for_female
        bma = hostel.blocks_for_male
        if set(bfe).intersection(set(bma)):
            raise Invalid(_('Female and male blocks overlap.'))

    @invariant
    def bedsOverlap(hostel):
        beds = (hostel.beds_for_fresh +
                hostel.beds_for_returning +
                hostel.beds_for_final +
                hostel.beds_for_all)
        if len(beds) != len(set(beds)):
            raise Invalid(_('Bed categories overlap.'))

class IBed(ISIRPObject):
    """A base representation of beds.

    """

    def loggerInfo(ob_class, comment):
        """Adds an INFO message to the log file
        """

    def getBedCoordinates():
        """Determine the coordinates from bed_id.
        """
    def bookBed(student_id):
        """Book a bed for a student.
        """

    def switchReservation():
        """Reserves bed or relases reserved bed respectively.
        """

    bed_id = schema.TextLine(
        title = _(u'Bed Id'),
        required = True,
        default = u'',
        )

    bed_type = schema.TextLine(
        title = _(u'Bed Type'),
        required = True,
        default = u'',
        )

    bed_number = schema.Int(
        title = _(u'Bed Number'),
        required = True,
        )

    owner = schema.TextLine(
        title = _(u'Owner (Student)'),
        required = True,
        default = u'',
        )



class IBedAllocateStudent(IBed):
    """A representation of beds for allocation form only.

    """

    owner = schema.Choice(
        title = _(u'Owner (Student)'),
        source = StudentSource(),
        default = None,
        required = True,
        )
