# Copyright (c) 2013, Mark Peek <mark@peek.org>
# All rights reserved.
#
# See LICENSE file for full license.

from . import AWSObject, Ref, GetAtt
from .validators import boolean, integer


class CacheCluster(AWSObject):
    resource_type = "AWS::ElastiCache::CacheCluster"

    props = {
        'AutoMinorVersionUpgrade': (boolean, False),
        'AZMode': (basestring, False),
        'CacheNodeType': (basestring, True),
        'CacheParameterGroupName': (basestring, False),
        'CacheSecurityGroupNames': ([basestring, Ref], False),
        'CacheSubnetGroupName': (basestring, False),
        'ClusterName': (basestring, False),
        'Engine': (basestring, True),
        'EngineVersion': (basestring, False),
        'NotificationTopicArn': (basestring, False),
        'NumCacheNodes': (integer, True),
        'Port': (integer, False),
        'PreferredAvailabilityZone': (basestring, False),
        'PreferredAvailabilityZones': ([basestring], False),
        'PreferredMaintenanceWindow': (basestring, False),
        'SnapshotArns': ([basestring, Ref], False),
        'SnapshotRetentionLimit': (integer, False),
        'SnapshotWindow': (basestring, False),
        'VpcSecurityGroupIds': ([basestring, Ref, GetAtt], False),
    }


class ParameterGroup(AWSObject):
    resource_type = "AWS::ElastiCache::ParameterGroup"

    props = {
        'CacheParameterGroupFamily': (basestring, True),
        'Description': (basestring, True),
        'Properties': (dict, True),
    }


class SecurityGroup(AWSObject):
    resource_type = "AWS::ElastiCache::SecurityGroup"

    props = {
        'Description': (basestring, False),
    }


class SecurityGroupIngress(AWSObject):
    resource_type = "AWS::ElastiCache::SecurityGroupIngress"

    props = {
        'CacheSecurityGroupName': (basestring, True),
        'EC2SecurityGroupName': (basestring, True),
        'EC2SecurityGroupOwnerId': (basestring, False),
    }


class SubnetGroup(AWSObject):
    resource_type = "AWS::ElastiCache::SubnetGroup"

    props = {
        'Description': (basestring, True),
        'SubnetIds': (list, True),
    }

@@ -1248,24 +1248,864 @@
 se),%0A    %7D%0A%0A
+    def validate(self):%0A        # Check that AZMode is %22cross-az%22 if more than one Availability zone%0A        # is specified in PreferredAvailabilityZones%0A        preferred_azs = self.properties.get('PreferredAvailabilityZones')%0A        if preferred_azs is not None and len(preferred_azs) %3E 1:%0A            if self.properties.get('AZMode') != 'cross-az':%0A                raise ValueError('AZMode must be %22cross-az%22 if more than one a'%0A                                 'vailability zone is specified in PreferredAv'%0A                                 'ailabilityZones: http://docs.aws.amazon.com/'%0A                                 'AWSCloudFormation/latest/UserGuide/aws-prope'%0A                                 'rties-elasticache-cache-cluster.html#cfn-ela'%0A                                 'sticache-cachecluster-azmode')%0A%0A        return True%0A%0A
 %0Aclass Param

Add validation for AZMode property on CacheCluster objects