     }
 }
 
+/**
+ The Events capability, generic over an EventsCapabilityRegistrarType. 
+ 
+ Framework consumers should not use this directly, but instead 
+ use Capability.Calendar. So that its usage is like this:
+ 
+ ```swift
+ 
+ GetAuthorizationStatus(Capability.Calendar()) { status in
+    // check the status etc.
+ }
+ ```
+ 
+ - see: Capability.Calendar
+*/
 public class _EventsCapability<Registrar: EventsCapabilityRegistrarType>: NSObject, CapabilityType {
 
+    /// - returns: a String, the name of the capability
     public let name: String
+
+    /// - returns: a EKEntityType, the required type of the capability
     public let requirement: EKEntityType
 
     let registrar: Registrar
 
+    /**
+     Initialize the capability. By default, it requires access to .Event.
+
+     - parameter requirement: the required EKEntityType, defaults to .Event
+     - parameter registrar: the registrar to use. Defauls to creating a Registrar.
+    */
     public required init(_ requirement: EKEntityType = .Event, registrar: Registrar = Registrar()) {
         self.name = "Events"
         self.requirement = requirement


import EventKit

public protocol EventsCapabilityRegistrarType: CapabilityRegistrarType {
    func opr_authorizationStatusForRequirement(requirement: EKEntityType) -> EKAuthorizationStatus
    func opr_requestAccessForRequirement(requirement: EKEntityType, completion: EKEventStoreRequestAccessCompletionHandler)
}

extension EKEventStore: EventsCapabilityRegistrarType {

    public func opr_authorizationStatusForRequirement(requirement: EKEntityType) -> EKAuthorizationStatus {
        return EKEventStore.authorizationStatusForEntityType(requirement)
    }

    public func opr_requestAccessForRequirement(requirement: EKEntityType, completion: EKEventStoreRequestAccessCompletionHandler) {
        requestAccessToEntityType(requirement, completion: completion)
    }

}

extension Capability {

    /**
     # Capability.Calendar
     
     For framework consumers - use with GetAuthorizationStatus, Authorize and
     AuthorizedFor. For example
     
     Get the current authorization status for accessing the user's calendars:

     ```swift
     GetAuthorizationStatus(Capability.Calendar()) { available, status in
         // etc
     }
     ```
     
     Lets say we have an operation which performs an action with the user's
     calendars. We need to have permission to access their calendars first.
     We can add an OperationCondition to such an operation, so that if
     the user hasn't granted permission it will fail (we can check the errors),
     or, if the permission hasn't been asked, it will ask for us automatically.
     
     ```swift

     // Define the operation
     let operation = ProcessCalendarsOperation()
     
     // Create & add condition
     let condition = AuthorizedFor(Capability.Calendar())
     operation.addCondition(condition)
     
     // Observe & look out for errors
     operation.addObserver(BlockObserver { _, errors in
        if !errors.isEmpty, 
          let error = errors.first as? CapabilityError<Capability.Calendar> {
             switch error {
               case .AuthorizationNotGranted(status, requirement):
                  print("Access to calendars was denied...")
             }
          }
     })
     
     // Add the operation to our queue
     queue.addOperation(operation)
     ```
    */
    public typealias Calendar = _EventsCapability<EKEventStore>
}

@available(*, unavailable, renamed="AuthorizedFor(Capability.Calendar())")
public typealias CalendarCondition = AuthorizedFor<Capability.Calendar>

