//
//  YSMASConstraintMaker.h
//  Masonry
//
//  Created by Jonas Budelmann on 20/07/13.
//  Copyright (c) 2013 cloudling. All rights reserved.
//

#import "YSMASConstraint.h"
#import "YSMASUtilities.h"

typedef NS_OPTIONS(NSInteger, YSMASAttribute) {
    YSMASAttributeLeft = 1 << NSLayoutAttributeLeft,
    YSMASAttributeRight = 1 << NSLayoutAttributeRight,
    YSMASAttributeTop = 1 << NSLayoutAttributeTop,
    YSMASAttributeBottom = 1 << NSLayoutAttributeBottom,
    YSMASAttributeLeading = 1 << NSLayoutAttributeLeading,
    YSMASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
    YSMASAttributeWidth = 1 << NSLayoutAttributeWidth,
    YSMASAttributeHeight = 1 << NSLayoutAttributeHeight,
    YSMASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
    YSMASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
    YSMASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
    
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
    
    YSMASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline,
    YSMASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline,
    
#endif
    
#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)
    
    YSMASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
    YSMASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
    YSMASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
    YSMASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
    YSMASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
    YSMASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
    YSMASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
    YSMASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,

#endif
    
};

/**
 *  Provides factory methods for creating YSMASConstraints.
 *  Constraints are collected until they are ready to be installed
 *
 */
@interface YSMASConstraintMaker : NSObject

/**
 *	The following properties return a new YSMASViewConstraint
 *  with the first item set to the makers associated view and the appropriate YSMASViewAttribute
 */
@property (nonatomic, strong, readonly) YSMASConstraint *left;
@property (nonatomic, strong, readonly) YSMASConstraint *top;
@property (nonatomic, strong, readonly) YSMASConstraint *right;
@property (nonatomic, strong, readonly) YSMASConstraint *bottom;
@property (nonatomic, strong, readonly) YSMASConstraint *leading;
@property (nonatomic, strong, readonly) YSMASConstraint *trailing;
@property (nonatomic, strong, readonly) YSMASConstraint *width;
@property (nonatomic, strong, readonly) YSMASConstraint *height;
@property (nonatomic, strong, readonly) YSMASConstraint *centerX;
@property (nonatomic, strong, readonly) YSMASConstraint *centerY;
@property (nonatomic, strong, readonly) YSMASConstraint *baseline;

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)

@property (nonatomic, strong, readonly) YSMASConstraint *firstBaseline;
@property (nonatomic, strong, readonly) YSMASConstraint *lastBaseline;

#endif

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)

@property (nonatomic, strong, readonly) YSMASConstraint *leftMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *rightMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *topMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *bottomMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *leadingMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *trailingMargin;
@property (nonatomic, strong, readonly) YSMASConstraint *centerXWithinMargins;
@property (nonatomic, strong, readonly) YSMASConstraint *centerYWithinMargins;

#endif

/**
 *  Returns a block which creates a new YSMASCompositeConstraint with the first item set
 *  to the makers associated view and children corresponding to the set bits in the
 *  YSMASAttribute parameter. Combine multiple attributes via binary-or.
 */
@property (nonatomic, strong, readonly) YSMASConstraint *(^attributes)(YSMASAttribute attrs);

/**
 *	Creates a YSMASCompositeConstraint with type YSMASCompositeConstraintTypeEdges
 *  which generates the appropriate YSMASViewConstraint children (top, left, bottom, right)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) YSMASConstraint *edges;

/**
 *	Creates a YSMASCompositeConstraint with type YSMASCompositeConstraintTypeSize
 *  which generates the appropriate YSMASViewConstraint children (width, height)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) YSMASConstraint *size;

/**
 *	Creates a YSMASCompositeConstraint with type YSMASCompositeConstraintTypeCenter
 *  which generates the appropriate YSMASViewConstraint children (centerX, centerY)
 *  with the first item set to the makers associated view
 */
@property (nonatomic, strong, readonly) YSMASConstraint *center;

/**
 *  Whether or not to check for an existing constraint instead of adding constraint
 */
@property (nonatomic, assign) BOOL updateExisting;

/**
 *  Whether or not to remove existing constraints prior to installing
 */
@property (nonatomic, assign) BOOL removeExisting;

/**
 *	initialises the maker with a default view
 *
 *	@param	view	any YSMASConstraint are created with this view as the first item
 *
 *	@return	a new YSMASConstraintMaker
 */
- (id)initWithView:(YSMAS_VIEW *)view;

/**
 *	Calls install method on any YSMASConstraints which have been created by this maker
 *
 *	@return	an array of all the installed YSMASConstraints
 */
- (NSArray *)install;

- (YSMASConstraint * (^)(dispatch_block_t))group;

@end
