class AttributeOptionComboDateCheck implements Checker {

    @Override
    public ImportSummary check( ImmutableEvent event, WorkContext ctx )
    {
        CategoryOptionCombo attributeOptionCombo = ctx.getCategoryOptionComboMap().get( event.getUid() );

        Date executionDate = null;

        if ( event.getEventDate() != null )
        {
            executionDate = DateUtils.parseDate( event.getEventDate() );
        }

        Date dueDate = new Date();

        if ( event.getDueDate() != null )
        {
            dueDate = DateUtils.parseDate( event.getDueDate() );
        }

        Date eventDate = executionDate != null ? executionDate : dueDate;

        if ( eventDate == null )
        {
            return error( "Event date can not be empty", event.getEvent() );
        }

        for ( CategoryOption categoryOption : attributeOptionCombo.getCategoryOptions() )
        {
            if ( categoryOption.getStartDate() != null && eventDate.compareTo( categoryOption.getStartDate() ) < 0 )
            {
                return error( "Event date " + getMediumDateString( eventDate ) + " is before start date "
                    + getMediumDateString( categoryOption.getStartDate() ) + " for attributeOption '"
                    + categoryOption.getName() + "'", event.getEvent() );
            }

            if ( categoryOption.getEndDate() != null && eventDate.compareTo( categoryOption.getEndDate() ) > 0 )
            {
                return error( "Event date " + getMediumDateString( eventDate ) + " is after end date "
                    + getMediumDateString( categoryOption.getEndDate() ) + " for attributeOption '"
                    + categoryOption.getName() + "'", event.getEvent() );
            }
        }

        return success();
    }

}