## $Id: interfaces.py 14204 2016-09-29 07:20:07Z henrik $
##
## Copyright (C) 2014 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
##

import re
from zope import schema
from waeup.ikoba.interfaces import IIkobaObject
from waeup.ikoba.schema import FormattedDate, PhoneNumber
from waeup.ikoba.customers.interfaces import (
    ICustomer, ICustomerDocument, ICustomerPDFDocument, IContract)
from waeup.ikoba.customers.vocabularies import (
    ConCatProductSource, CustomerDocumentSource, nats_vocab)
from waeup.ikoba.products.productoptions import ProductOptionField
from ikobacustom.uniben.interfaces import MessageFactory as _

class NotUnibenEmailAddress(schema.ValidationError):
    __doc__ = u"Invalid Uniben email address"

check_email = re.compile(
    r"^[^@\s,]+@[^@\.\s,]+(\.[^@\.\s,]+)*$").match

def validate_uniben_email(value):
    if not check_email(value):
        raise NotUnibenEmailAddress(value)
    if not value.endswith('uniben.edu'):
        raise NotUnibenEmailAddress(value)
    return True

class IUnibenCustomer(ICustomer):
    """Representation of a customer.

    """

# Customer document interfaces


class IUnibenCustomerJPGDocument(ICustomerDocument):
    """A customer document.

    """

class IUnibenCustomerPDFDocument(ICustomerPDFDocument):
    """A customer pdf document.

    """

# Customer contract interfaces

class IUnibenContract(IContract):
    """A customer contract with document attached.

    """

    nominator_title_rank = schema.TextLine(
        title = _(u'Title/Rank'),
        required = False,
        )

    nominator_nationality = schema.Choice(
        vocabulary = nats_vocab,
        title = _(u'Current Nationality'),
        required = False,
        )

    nominator_address = schema.Text(
        title = _(u'Affiliation/Address'),
        required = False,
        )

    nominee_fullname = schema.TextLine(
        title = _(u'Name'),
        description = u'Surname last and in capital letters',
        required = False,
        )

    nominee_title_rank = schema.TextLine(
        title = _(u'Title/Rank'),
        required = False,
        )

    nominee_department = schema.TextLine(
        title = _(u'Department/Faculty/Institute'),
        required = False,
        )

    nominee_date_of_birth = FormattedDate(
        title = _(u'Date of Birth'),
        required = False,
        show_year = True,
        )

    nominee_nationality = schema.Choice(
        vocabulary = nats_vocab,
        title = _(u'Current Nationality'),
        required = False,
        )

    nominee_email = schema.ASCIILine(
        title = _(u'Uniben Email Address'),
        required = False,
        constraint=validate_uniben_email,
        )

    nominee_phone = PhoneNumber(
        title = _(u'Phone'),
        description = u'',
        required = False,
        )

    app_dates = schema.Text(
        title = _(u'Date of Appointment as Uniben staff'),
        description = u'State periods nominee had a break in service from '
                       'UNIBEN service (including leave of absence), '
                       'but excluding training/study/sabbatical leave',
        required = False,
        )

    bib_cit = schema.Text(
        title = _(u'Biographical Citation'),
        description = u'Suggested biographical citation of '
                       'nominee (max. 200 words) in the event that the '
                       'nominee is selected for the award.',
        required = False,
        )

    sup_stat = schema.Text(
        title = _(u'Supporting Statement'),
        description = u'Supporting statement (max. 200 words) summarizing '
                       'the research and innovative achievement of the '
                       'candidate. It should preferably focus on one major '
                       'achievement/innovation/accomplishment.',
        required = False,
        )

    nar_wu = schema.Text(
        title = _(u'Narrative Write-Up'),
        description = u'A narrative write-up (max. 1,000 words) of the '
                       'candidate highlighting his/her scientific/creative '
                       'achievement and/or innovation; restrict to one major '
                       'innovation/achievement/accomplishment. '
                       'The national/international impact of the '
                       'achievement/innovation should be emphasized.',
        required = False,
        )

    item_stat = schema.Text(
        title = _(u'Itemized Statement'),
        description = u'Itemized statement of research leadership and '
                        'collaboration (max. 100 words)',
        required = False,
        )

    sign_pub = schema.Text(
        title = _(u'Significant Publications'),
        description = u'A list of his/her most significant publications '
                       '(max. 10) pertaining to the achievement/innovation '
                       'along with each publication\'s H-index',
        required = False,
        )

    prev_aw = schema.Text(
        title = _(u'Previous Awards'),
        description = u'List of previous awards, honours and recognition '
                       '(max. 10) received by nominee, including awarding '
                       'body, purpose of award, date of award, and nature '
                       'of award (cash, certificate, plaque, etc)',
        required = False,
        )

    lead_rol = schema.Text(
        title = _(u'Leadership Roles'),
        description = u'List of leadership roles in academic/professional '
                       'societies/organizations (max. no. of 3)',
        required = False,
        )

    h_index = schema.Text(
        title = _(u'State H-Index'),
        description = u'State the full H-index of author, i.e. nominee',
        required = False,
        )

    passport = schema.Choice(
        title = _(u'Passport Photo'),
        source = CustomerDocumentSource(),
        required = False,
        )

    vitae_doc = schema.Choice(
        title = _(u'Curriculum Vitae'),
        source = CustomerDocumentSource(),
        description = u'A curriculum vitae including a full list of scholarly '
                       'publications',
        required = False,
        )

    ref1_doc = schema.Choice(
        title = _(u'Reference Letter 1'),
        source = CustomerDocumentSource(),
        required = False,
        )

    ref2_doc = schema.Choice(
        title = _(u'Reference Letter 2'),
        source = CustomerDocumentSource(),
        required = False,
        )

    ref3_doc = schema.Choice(
        title = _(u'Reference Letter 3'),
        source = CustomerDocumentSource(),
        required = False,
        )

    photo1 = schema.Choice(
        title = _(u'Photo or Illustration 1'),
        source = CustomerDocumentSource(),
        description = u'(optional)',
        required = False,
        )


    photo2 = schema.Choice(
        title = _(u'Photo or Illustration 2'),
        source = CustomerDocumentSource(),
        description = u'(optional)',
        required = False,
        )

    photo3 = schema.Choice(
        title = _(u'Photo or Illustration 3'),
        source = CustomerDocumentSource(),
        description = u'(optional)',
        required = False,
        )

class IRIAAContract(IUnibenContract):
    """A Retention of Name contract.

    """

class IRIAAContractOfficialUse(IIkobaObject):
    """Interface for editing RIAA official use data.

    """

    comment = schema.Text(
        title= _('Reason for rejection'),
        required = False,
        )


class IRIAAContractProcess(IRIAAContract, IRIAAContractOfficialUse):
    """Interface for processing RIAA data.
    """

    product_options = schema.List(
        title = _(u'Options/Fees'),
        value_type = ProductOptionField(),
        required = False,
        readonly = False,
        defaultFactory=list,
        )

class IRIAAContractEdit(IRIAAContract):
    """Interface for editing RIAA data by customers.

    """

