//
//  GlobalNetManager.m
//  fastservice
//
//  Created by xuning on 5/8/25.
//  Copyright © 2025 FastService. All rights reserved.
//

#import "GlobalNetManager.h"
#import "XVLoginViewController.h"
#import "XVNaviViewController.h"

@interface GlobalNetManager()
@property (nonatomic,strong) NSTimer *timer;
@property (nonatomic,assign) float timer_count;

// 骑士在线时长统计
@property (nonatomic,strong) NSTimer *onlineTimer;
@property (nonatomic,assign) float online_duration;

@property (nonatomic, strong) UserInfo *userInfo;

@end

@implementation GlobalNetManager
DEF_SINGLETION(GlobalNetManager);
- (instancetype)init{
    self = [super init];
    if (self) {
        self.timer_count = 30000;
        self.online_duration = 60000;
    }
    return self;
}


- (void)logout:(EventHandler)logoutBlock{
    
    if (![AppConfig needLogin]) {
        [AppConfig clearUserInfo];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:kAppUserLogout object:nil];
        BlockCallWithOneArg(logoutBlock, @"logout");
        
        [[AFNetworkingClient sharedClient]runPost:SS_LOGOUT parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
            if ([MyNetWork isSuccessServerData:responseObject]) {
                DebugLog(@"退出app成功");
            }else{
                DebugLog(@"退出app失败resperr：%@",responseObject[@"resperr"]);
            }
        } failure:^(NSURLSessionDataTask *task, NSError *error) {
            DebugLog(@"退出app失败");
        }];
        
        // 重置登录页面
        XVLoginViewController *loginVc = [[XVLoginViewController alloc]init];
        XVNaviViewController *navi = [[XVNaviViewController alloc]initWithRootViewController:loginVc];

        theApp().window.rootViewController = navi;

        
    }
    
//    if ([EMClient sharedClient].isLoggedIn) {
//        [[EMClient sharedClient] logout:YES completion:^(EMError *aError) {
//            if (aError) {
//                DebugLog(@"环信退出失败：%@",aError.errorDescription);
//            }else{
//                DebugLog(@"环信退出成功：%@",aError.errorDescription);
//            }
//        }];
//    }
}

- (void)logout:(EventHandler)logoutBlock:(XVBaseViewController *)bvc{
    [self logout:logoutBlock];
}


@end
