# Path: openprocurement/tender/openua/constants.py
# TENDERING_EXTRA_PERIOD = timedelta(days=7)


from openprocurement.api.utils import (
    upload_file, context_unpack, json_view,
    update_file_content_type, get_now, error_handler, raise_operation_error
)
from openprocurement.tender.core.utils import (
    save_tender,
    apply_patch,
    optendersresource,
    calculate_business_date
)
from openprocurement.api.validation import validate_file_upload, validate_file_update, validate_patch_document_data
from openprocurement.tender.core.validation import (
    validate_document_operation_in_not_allowed_period,
    validate_tender_document_update_not_by_author_or_tender_owner
)
from openprocurement.tender.belowthreshold.views.tender_document import TenderDocumentResource
from openprocurement.tender.openua.constants import TENDERING_EXTRA_PERIOD


@optendersresource(name='aboveThresholdUA:Tender Documents',
                   collection_path='/tenders/{tender_id}/documents',
                   path='/tenders/{tender_id}/documents/{document_id}',
                   procurementMethodType='aboveThresholdUA',
                   description="Tender UA related binary files (PDFs, etc.)")
class TenderUaDocumentResource(TenderDocumentResource):

    def validate_update_tender(self):
        """ TODO move validators
        This class is inherited in cd stage 2 package, but validate_update_tender function has different validators.
        For now, we have no way to use different validators on methods according to procedure type.
        """

# Path: openprocurement/tender/openua/constants.py
# TENDERING_EXTRA_PERIOD = timedelta(days=7)


# Path: openprocurement/tender/openua/views/tender_document.py
from openprocurement.api.utils import (
    upload_file, context_unpack, json_view,
    update_file_content_type, get_now, error_handler, raise_operation_error
)
from openprocurement.tender.core.utils import (
    save_tender,
    apply_patch,
    optendersresource,
    calculate_business_date
)
from openprocurement.api.validation import validate_file_upload, validate_file_update, validate_patch_document_data
from openprocurement.tender.core.validation import (
    validate_document_operation_in_not_allowed_period,
    validate_tender_document_update_not_by_author_or_tender_owner
)
from openprocurement.tender.belowthreshold.views.tender_document import TenderDocumentResource
from openprocurement.tender.openua.constants import TENDERING_EXTRA_PERIOD



@optendersresource(name='aboveThresholdUA:Tender Documents',
                   collection_path='/tenders/{tender_id}/documents',
                   path='/tenders/{tender_id}/documents/{document_id}',
                   procurementMethodType='aboveThresholdUA',
                   description="Tender UA related binary files (PDFs, etc.)")
class TenderUaDocumentResource(TenderDocumentResource):

    def validate_update_tender(self):
        """ TODO move validators
        This class is inherited in cd stage 2 package, but validate_update_tender function has different validators.
        For now, we have no way to use different validators on methods according to procedure type.
        """

        if self.request.validated['tender_status'] == 'active.tendering' and calculate_business_date(get_now(), TENDERING_EXTRA_PERIOD, self.request.validated['tender']) > self.request.validated['tender'].tenderPeriod.endDate: