//
//  DOWebRoute.h
//  DOCore
//
//  Created by Ben Dolman on 3/3/15.
//
//

#import <Foundation/Foundation.h>

typedef NS_OPTIONS(NSInteger, DOHTTPMethod) {
    DOHTTPMethodGET             = 1 << 0,
    DOHTTPMethodPOST            = 1 << 1,
    DOHTTPMethodPUT             = 1 << 2,
    DOHTTPMethodDELETE          = 1 << 3,
    DOHTTPMethodHEAD            = 1 << 4,
    DOHTTPMethodPATCH           = 1 << 5,
    DOHTTPMethodOPTIONS         = 1 << 6,
    DOHTTPMethodAny             = (DOHTTPMethodGET |
                                   DOHTTPMethodPOST |
                                   DOHTTPMethodPUT |
                                   DOHTTPMethodDELETE |
                                   DOHTTPMethodHEAD |
                                   DOHTTPMethodPATCH |
                                   DOHTTPMethodOPTIONS)
};

extern DOHTTPMethod DOHTTPMethodFromString(NSString *method);

/**
 * A route is an HTTP path + verb. Example: GET /api/user
 */
@interface DOHTTPRoute : NSObject <NSCopying>

@property (copy, readonly) NSString *path;
@property (assign, readonly) DOHTTPMethod method;

/**
 * Creates a new route with a path pattern and an HTTP method.
 *
 * @param path A regular expression string to match a path
 * @param method A mask of methods to which this route matches. You can have more than one.
 */
+ (instancetype)routeWithPath:(NSString *)path method:(DOHTTPMethod)method;

- (BOOL)evaluateRequest:(NSURLRequest *)request;
- (BOOL)evaluateURL:(NSURL *)URL method:(NSString *)method;

@end
