//
//  ValetDefines.h
//  Valet
//
//  Created by Dan Federman on 2/11/15.
//  Copyright 2015 Square, Inc.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

/**
 Throws a caught exception and returns "result" if "condition" is false.
 
 Example:
 VALCheckCondition(isProperlyConfigured, nil, @"Foo was not properly configured.");
 
 */
#define VALCheckCondition(condition, result, desc, ...) \
    do { \
        const BOOL conditionResult = !!(condition); \
        if (!conditionResult) { \
            @try { \
                [NSException raise:@"Valet API Misuse" format:(desc), ##__VA_ARGS__]; \
            } @catch (NSException *exception) { \
                NSLog(@"Valet API Misuse: %s %@", __PRETTY_FUNCTION__, exception.reason); \
                return result;\
            } \
        } \
    } while(0)

/// Compile flag for building against iOS 8.
#define VAL_IOS_8_OR_LATER (TARGET_OS_IPHONE && __IPHONE_8_0)

/// Compile flag for building against iOS 9.
#define VAL_IOS_9_OR_LATER (TARGET_OS_IPHONE && __IPHONE_9_0)

/// Error returned from Security API when the application is not entitled to perform the requested action.
#define errSecMissingEntitlement -34018
