//
//  TikTokOpenSDKAuth.h
//
//  Created by ByteDance on 2019/7/8.
//  Copyright (c) 2018年 ByteDance Ltd. All rights reserved.
//

#import "TikTokOpenSDKApplicationDelegate.h"
#import "TikTokOpenSDKObjects.h"

NS_ASSUME_NONNULL_BEGIN

@class TikTokOpenSDKAuthResponse;

typedef void (^TikTokOpenSDKAuthCompletionBlock)(TikTokOpenSDKAuthResponse *resp);//!< Auth Result callback block
typedef void (^TikTokOpenSDKAuthCompleteBlock)(TikTokOpenSDKAuthResponse *resp) DEPRECATED_MSG_ATTRIBUTE("Use 'TikTokOpenSDKAuthCompletionBlock' instead");

#pragma mark - Auth Request

@interface TikTokOpenSDKAuthRequest : TikTokOpenSDKBaseRequest


/**
   The type of required permission applied by the third-party application to Open Platform is finally returned to the third-party application based on the actual authorization result after the App authorization is completed
   e.g. [NSOrderedSet orderedSetWithObjects:@"user.info.basic", ..., nil]

 */
@property (nonatomic, strong, nullable) NSOrderedSet<NSString *> *permissions;

/**
   The additional permission type that the third-party application applies to Open Platform, the user can check whether to grant this part of the permission, and finally return to the third-party application according to the actual authorization result after the App authorization is completed;
   @key permission
   @key defaultChecked Initial check state, @"1" means check, @"0" means unchecked
   e.g. [NSOrderedSet orderedSetWithObjects:@{@"permission":@"user.info.basic",@"defaultChecked":@"0"}, ..., nil]
 */
@property (nonatomic, strong, nullable) NSOrderedSet<NSDictionary<NSString *, NSString *> *> *additionalPermissions;

/**
   Used to identify the uniqueness of the request, and finally returned by App when jumping back to the third-party program
 */
@property (nonatomic, copy, nullable) NSString *state;

/**
 * @brief Send authorization request to Open Platform. If not install App will open authorized web page.

 *
 * @param viewController The view controller which show authorized web page
 * @param completion      The async result call back. You can get reslut via resp.isSucceed.
 *
 * @return Authorization request is valid will return YES;
 */
- (BOOL)sendAuthRequestViewController:(UIViewController *)viewController
                           completion:(TikTokOpenSDKAuthCompletionBlock)completion;

#pragma mark - Deprecated

- (BOOL)sendAuthRequestViewController:(UIViewController *)viewController
                        completeBlock:(TikTokOpenSDKAuthCompleteBlock)completed DEPRECATED_MSG_ATTRIBUTE("Use 'sendAuthRequestViewController:completion:' instead");

@end


#pragma mark - Auth Response

@interface TikTokOpenSDKAuthResponse : TikTokOpenSDKBaseResponse

/**
   You apply for certain permissions to Open Platform, and finally return to the third-party application based on the actual authorization result after the App authorization is completed.
 */
@property (nonatomic, copy, readonly, nullable) NSString *code;

/**
   State can be used to identify the uniqueness of the request, and finally returned by Open Platform when jumping back to a third-party program
 */
@property (nonatomic, copy, readonly, nullable) NSString *state;

/**
   The users agree to give your applications permission, if the authorization is successful, all necessary permissions and additional permissions checked by the user;
 */
@property (nonatomic, strong, nullable) NSOrderedSet<NSString *> *grantedPermissions;

@end


NS_ASSUME_NONNULL_END
