#import <Foundation/Foundation.h>
#import <ZSM/ZSMClient.h>

NS_ASSUME_NONNULL_BEGIN
/**
 * `ZSM` manages security tasks such as activation, checking status, managing keys, and handling signatures.
 */
@interface CryptoClient : ZSMClient

#pragma mark - Registration and initialization

- (instancetype)init NS_UNAVAILABLE;

#pragma mark - Key management

/**
 * Generates a cryptographic key.
 * @param completion Callback to be invoked upon key generation completion.
 */
- (void)generateKeyWithCompletion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(generateKey(completion:));

/**
 * Generates a new cryptographic key.
 * @param headers Optional headers which will be merged with any headers specified in the initializer.
 * @param metadata Optional meta data for server.
 * @param completion Callback to be invoked upon key generation completion.
 */
- (void)generateKeyWithHeaders:(nullable NSDictionary<NSString *, NSString *> *)headers
                        metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata
                      completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(generateKey(headers:metadata:completion:));

/**
 * Refreshes the cryptographic key.
 * @param completion Callback to be invoked upon key refresh completion.
 */
- (void)refreshKeyWithCompletion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(refreshKey(completion:));

/**
 * Refreshes the current cryptographic key.
 * @param headers Optional headers which will be merged with any headers specified in the initializer and sent to the server.
 * @param metadata Optional meta which will be merged with any headers specified in the initializer and sent to the server.
 * @param completion Callback to be invoked upon key refresh completion.
 */
- (void)refreshKeyWithHeaders:(nullable NSDictionary<NSString *, NSString *> *)headers
                     metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata
                   completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(refreshKey(headers:metadata:completion:));

/**
 * Imports a cryptographic key from a PEM-encoded string.
 * @param pem PEM-encoded key data.
 * @param completion Callback to be invoked upon key import completion.
 */
- (void)importKey:(nonnull NSData *)pem
       completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(importKey(from:completion:));

/**
 * Imports a cryptographic key from a PEM-encoded string.
 * @param pem PEM-encoded key data.
 * @param headers Optional headers which will be merged with any headers specified in the initializer and sent to the server.
 * @param metadata Optional meta which will be merged with any headers specified in the initializer and sent to the server.
 * @param completion Callback to be invoked upon key import completion.
 */
- (void)importKey:(nonnull NSData *)pem
          headers:(nullable NSDictionary<NSString *, NSString *> *)headers
         metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata
       completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(importKey(from:headers:metadata:completion:));

/**
 * Deletes a cryptographic key.
 * @param completion Callback to be invoked upon key deletion completion.
 */
- (void)deleteKeyWithCompletion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(deleteKey(completion:));

/**
 * Deletes a cryptographic key.
 * @param headers Optional headers which will be merged with any headers specified in the initializer and sent to the server.
 * @param metadata Optional meta which will be merged with any headers specified in the initializer and sent to the server.
 * @param completion Callback to be invoked upon key deletion completion.
 */
- (void)deleteKeyWithHeaders:(nullable NSDictionary<NSString *, NSString *> *)headers
                    metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata
                  completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(deleteKey(headers:metadata:completion:));

#pragma mark - Encryption and signing

/**
 * Generates a signature for the specified message using the current cryptographic key using the algorithm specified in configuration
 * @param message Message to sign.
 * @param completion Callback to be invoked upon signature generation completion.
 */
- (void)generateSignatureForMessage:(nonnull NSData*)message
                         completion:(ZSMSignCompletion)completion
NS_SWIFT_NAME(generateSignature(_:completion:));

/**
 * Generates a signature for the specified message using the current cryptographic key.
 * @param message Message to sign.
 * @param headers Optional headers which will be merged with any headers specified in the initializer and sent to the server.
 * @param metadata Optional meta which will be merged with any headers specified in the initializer and sent to the server.
 * @param refresh Refresh keys if true.
 * @param completion Callback to be invoked upon signature generation completion.
 */
- (void)generateSignatureForMessage:(nonnull NSData*)message
                            headers:(nullable NSDictionary<NSString *, NSString *> *)headers
                           metadata:(nullable NSDictionary<NSString *, NSString *> *)metadata
                            refresh:(BOOL)refresh
                         completion:(ZSMSignCompletion)completion
NS_SWIFT_NAME(generateSignature(_:headers:metadata:refresh:completion:));

/**
 * Verifies the specified signature for the specified message using the current cryptographic key.
 * @param signature Signature data to verify.
 * @param message Original message for verification.
 * @param publicKey Optional public key for verification. Defaults to client keyset
 * @param completion Callback to be invoked upon signature verification completion.
 */
- (void)verifySignature:(nonnull NSData *)signature
                message:(nonnull NSData*)message
              publicKey:(nullable NSData*)publicKey
             completion:(ZSMBooleanCompletion)completion
NS_SWIFT_NAME(verifySignature(_:message:publicKey:completion:));

@end

NS_ASSUME_NONNULL_END
