//
//  SLUserModel.m
//  SLAiELTS
//
//  Created by Gusont on 2023/3/1.
//

#import "SLUserModel.h"

@interface SLUserModel()

///
@property (nonatomic, strong) NSString * name;

///
@property (nonatomic, strong) NSString * head;

@end

@implementation SLUserModel

+ (NSDictionary *)mj_replacedKeyFromPropertyName {
   return @{
            @"userId" : @"id"};
}

- (void)setHead:(NSString *)head {
    _head = head;
    _userHead = head;
}

- (void)setName:(NSString *)name {
    _name = name;
    _userName = name;
}

+ (void)requestUserRoleModel {
    NSString *userId = [SLGlobalInfo SharedInstance].loginInfo.user.userId;
    if (userId) {
        [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/HomePage" parameter:@{} success:^(id responseObject) {
            NSDictionary *dict = [responseObject objectForKey:@"data"];
            NSDictionary *modelDict = [dict objectForKey:@"list"];
            [SLGlobalInfo SharedInstance].roleModel = [RoleModel mj_objectWithKeyValues:modelDict];
            [SLGlobalInfo SharedInstance].loginInfo.isAiData = [[dict objectForKey:@"isAiData"] boolValue];
        } failure:^(SPRequestError *error) {
            
        }];
        [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/GetUserGoal" parameter:@{} success:^(id responseObject) {
            NSDictionary *dict = [responseObject objectForKey:@"data"];
            if ([dict isKindOfClass:NSDictionary.class]) {
                [SLGlobalInfo SharedInstance].targetModel = [SLTargetModel mj_objectWithKeyValues:dict];
            }
        } failure:^(SPRequestError *error) {
            
        }];
    }
}

- (NSString *)getUserHeadUrl {
    NSString *userImg = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, self.userHead];
    return userImg;
}

@end
