//
//  RDSDeviceTypeModel.m
//  Temperature
//
//  Created by 姓二名哈字富贵儿 on 2023/8/17.
//

#import "RDSDeviceTypeModel.h"

@implementation RDSDeviceTypeModel

- (NSString * _Nullable)getDeviceNameWithIndex:(NSInteger)index {
    if (index < self.deviceTypeList.count) {
        RDSDeviceTypeModel *deviceTypeModel = self.deviceTypeList[index];
        return deviceTypeModel.name;
    }
    return nil;
}

- (void)rds_fetchDeviceTypeListFinished:(void (^)(NSError * _Nullable))finished {
    [RDSDemoApiHelper rds_getDeviceTypeListSuccess:^(id responseObject) {
        NSLog(@"responseObject is %@", responseObject);
        if ([responseObject[@"code"] integerValue] == 0) {
            NSDictionary *data = responseObject[@"data"];
            [RDSDeviceTypeModel mj_setupObjectClassInArray:^NSDictionary *{
                return @{@"children": @"RDSDeviceTypeModel"};
            }];
            self->_deviceTypeList = [RDSDeviceTypeModel mj_objectArrayWithKeyValuesArray:data];
            BLOCK_SAFE_RUN(finished, nil)
        } else {
            NSError *error = [NSError errorWithDomain:responseObject[@"message"] code:[responseObject[@"code"] intValue] userInfo:nil];
            BLOCK_SAFE_RUN(finished, error)
        }
    } failure:^(NSError *error) {
        BLOCK_SAFE_RUN(finished, error)
    }];
}

@end
