# -*- coding: utf-8 -*-
from schematics.types import StringType
from zope.interface import implementer
from openprocurement.api.models import ITender
from openprocurement.tender.openua.models import Tender as TenderUA
from openprocurement.tender.openeu.models import Tender as TenderEU


@implementer(ITender)
class Tender(TenderUA):
    procurementMethodType = StringType(default="competitiveDialogue.aboveThresholdUA")


CompetitiveDialogUA = Tender


@implementer(ITender)
class Tender(TenderEU):
    procurementMethodType = StringType(default="competitiveDialogue.aboveThresholdEU")


CompetitiveDialogEU = Tender

@@ -17,16 +17,47 @@
 f-8 -*-%0A
+from datetime import timedelta%0A
 from sch
@@ -88,16 +88,66 @@
 ingType%0A
+from schematics.exceptions import ValidationError%0A
 from zop
@@ -223,16 +223,25 @@
  ITender
+, get_now
 %0Afrom op
@@ -373,141 +373,841 @@
 rEU%0A
-%0A%0A@implementer(ITender)%0Aclass Tender(TenderUA):%0A    procurementMethodType = StringType(default=%22competitiveDialogue.aboveThresholdUA%22
+from openprocurement.tender.openeu.models import TENDERING_DAYS, TENDERING_DURATION%0Afrom openprocurement.tender.openua.utils import calculate_business_date%0A%0A%0A@implementer(ITender)%0Aclass Tender(TenderUA):%0A    procurementMethodType = StringType(default=%22competitiveDialogue.aboveThresholdUA%22)%0A%0A    def validate_tenderPeriod(self, data, period):%0A        # if data%5B'_rev'%5D is None when tender was created just now%0A        if not data%5B'_rev'%5D and calculate_business_date(get_now(), -timedelta(minutes=10)) %3E= period.startDate:%0A            raise ValidationError(u%22tenderPeriod.startDate should be in greater than current date%22)%0A        if period and calculate_business_date(period.startDate, TENDERING_DURATION, data) %3E period.endDate:%0A            raise ValidationError(u%22tenderPeriod should be greater than %7B%7D days%22.format(TENDERING_DAYS)
 )%0A%0A%0A

add tenderPeriod validation