//
// © 2018-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NSError+IoTErrors.h"

NSString * const IoTErrorDomain = @"IoTErrorDomain";

@implementation NSError(IoTErrors)

+ (NSError *)errorWithIoTError:(IoTError)errorCode description:(NSString *)description
{
    NSDictionary * info = [[NSDictionary alloc] initWithObjectsAndKeys:description ?: [self descriptionForErrorCode:errorCode], NSLocalizedDescriptionKey, nil];

    return [[NSError alloc] initWithDomain:IoTErrorDomain
                                       code:errorCode userInfo:info];
}

+ (NSString *)descriptionForErrorCode:(IoTError)errorCode
{
    switch (errorCode) {
        case IoTErrorNone:
            return @"No error";
            break;
        case IoTErrorUnknown:
            return @"Unknown";
            break;
        case IoTErrorRequest:
            return @"Request";
            break;
        case IoTErrorNetwork:
            return @"Network";
            break;
        case IoTErrorFormat:
            return @"Format";
            break;
        case IoTErrorStream:
            return @"Stream";
            break;
        case IoTErrorAuthentication:
            return @"Authentication";
            break;
        case IoTErrorMediaRulesEngine:
            return @"MediaRulesEngine";
            break;
        case IoTErrorInvalidObject:
            return @"InvalidObject";
            break;
        case IoTErrorAuthenticationCancelled:
            return @"AuthenticationCancelled";
            break;
        case IoTErrorNotSupported:
            return @"NotSupported";
            break;
        case IoTErrorPartyModeDisabledPlayer:
            return @"PartyModeDisabledPlayer";
            break;
    }
}

@end
