import WebIdVideoIdentProductPlugin
import WebIdIosSdk
import WebIdPluginCore


// EVENTS

enum WebIdSdkEvent {
    case finishedFailed
    case finishedSuccess
    
    var codeValue: String {
        switch self {
        case .finishedFailed:
            return "WebIdSdkEvent.finishedFailed"
        case .finishedSuccess:
            return "WebIdSdkEvent.finishedSuccess"
        }
    }
}


// SUCCESS

enum WebIdSdkSuccess {
    case CoreSDKCreated
    case PluginStarted
    
    var codeValue: String {
        switch self {
        case .CoreSDKCreated:
            return "WebIdSdkSuccess.CoreSDKCreated"
        case .PluginStarted:
            return "WebIdSdkSuccess.PluginStarted"
        }
    }
}


// ERRORS

enum WebIdSdkGenericError {
    case UnknownException
    case SDKNotInitialized
    case MissingVerifyActionIdResult
    
    var codeValue: String {
        switch self {
        case .UnknownException:
            return "WebIdSdkGenericError.UnknownException";
        case .SDKNotInitialized:
            return "WebIdSdkGenericError.SDKNotInitialized";
        case .MissingVerifyActionIdResult:
            return "WebIdSdkGenericError.MissingVerifyActionIdResult";
        }
    }
    
    var messageValue: String {
        switch self {
        case .SDKNotInitialized:
            return "call createMetaPlugin() first"
        case .MissingVerifyActionIdResult:
            return "call verifyActionId() first"
        default:
            return ""
        }
    }
}

extension WebIdIosSdk.WebIdSdkEnvironmentError {
    var codeValue: String {
        switch self {
        case .PinningCertificateMissing:
            return "WebIdSdkEnvironmentError.PinningCertificateMissing";
        case .InvalidUrl:
            return "WebIdSdkEnvironmentError.InvalidUrl";
        @unknown default:
            return "WebIdSdkEnvironmentError.Unknown";
        }
    }
    var messageValue: String {
        return ""
    }
}


extension WebIdIosSdk.WebIdMobileAppSdkError {
    var codeValue: String {
        switch self {
        case .IllegalArgument(_):
            return "WebIdMobileAppSdkError.IllegalArgument"
        case .ApiToDomainCoversionFailed:
            return "WebIdMobileAppSdkError.ApiToDomainCoversionFailed"
        case .AccessDenied:
            return "WebIdMobileAppSdkError.AccessDenied"
        case .AuthenticationFailed:
            return "WebIdMobileAppSdkError.AuthenticationFailed"
        case .NSURLErrorDomain(_):
            return "WebIdMobileAppSdkError.NSURLErrorDomain"
        case .HttpError(_, _):
            return "WebIdMobileAppSdkError.HttpError"
        case .FatalError(_):
            return "WebIdMobileAppSdkError.FatalError"
        case .CertificatePinningFailed:
            return "WebIdMobileAppSdkError.CertificatePinningFailed"
        case .NetworkConnectionFailed:
            return "WebIdMobileAppSdkError.NetworkConnectionFailed"
        case .ServiceUnavailableException(_):
            return "WebIdMobileAppSdkError.ServiceUnavailableException"
        @unknown default:
            return "WebIdMobileAppSdkError.Unknown";
        }
    }
    
    var messageValue: String {
        switch self {
        case .IllegalArgument(let message):
            return message ?? ""
        case .NSURLErrorDomain(let error):
            return error.localizedDescription
        case .HttpError(let statusCode, _):
            return String(statusCode)
        case .FatalError(let error):
            return error.localizedDescription
        case .ServiceUnavailableException(let date):
            return date != nil ? ISO8601DateFormatter().string(from: date!) : ""
        default:
            return "";
        }
    }
}

extension WebIdIosSdk.UserActionError {
    var codeValue: String {
        switch self {
        case .EidAuthadaRequired(_):
            return "UserActionError.EidAuthadaRequired"
        case .IdentNotSupported(_):
            return "UserActionError.IdentNotSupported"
        case .IllegalState:
            return "UserActionError.IllegalState"
        case .NotFound:
            return "UserActionError.NotFound"
        case .SessionExpired:
            return "UserActionError.SessionExpired"
        @unknown default:
            return "UserActionError.Unknown \(self)";
        }
    }
    
    var messageValue: String {
        switch self {
        case .EidAuthadaRequired(let entryLink):
            return entryLink.link.url != nil ? entryLink.link.url!.absoluteString : ""
        case .IdentNotSupported(let entryLink):
            return entryLink.link.url != nil ? entryLink.link.url!.absoluteString : ""
        default:
            return "";
        }
    }
}

extension WebIdPluginCore.EProductPluginErrors {
    var codeValue: String {
        switch self {
        case .unknown(_):
            return "EProductPluginErrors.unknown"
        case .canceledByUser(_):
            return "EProductPluginErrors.canceledByUser"
        case .notAllowed(_, _):
            return "EProductPluginErrors.notAllowed"
        case .technical(_):
            return "EProductPluginErrors.technical"
        case .api(_):
            return "EProductPluginErrors.api"
        case .serviceUnavailable(_, _):
            return "EProductPluginErrors.serviceUnavailable"
        case .sessionExpired(_):
            return "EProductPluginErrors.sessionExpired"
        case .notAuthenticated(_):
            return "EProductPluginErrors.notAuthenticated"
        case .notAuthorized(_):
            return "EProductPluginErrors.notAuthorized"
        case .userActionNotFound(_):
            return "EProductPluginErrors.userActionNotFound"
        case .pluginInterrupted(_):
            return "EProductPluginErrors.pluginInterrupted"
        case .pluginStartFailed(_):
            return "EProductPluginErrors.pluginStartFailed"
        case .productSelectionRequired(_):
            return "EProductPluginErrors.productSelectionRequired"
        case .switchedToProduct(_, _):
            return "EProductPluginErrors.switchedToProduct"
        @unknown default:
            return "EProductPluginErrors.unknown"
        }
    }
    
    var messageValue: String {
        switch self {
        case .notAllowed(_, let entryLink):
            return entryLink != nil && entryLink!.link.url != nil ? entryLink!.link.url!.absoluteString : ""
        case .serviceUnavailable(_, let date):
            return date != nil ? ISO8601DateFormatter().string(from: date!) : ""
        case .switchedToProduct(_, let product):
            return product.stringValue
        default:
            return ""
        }
    }
}

// ENUMS

extension WebIdIosSdk.EUserActionType {
    var stringValue: String {
        switch self {
        case .age16:
            return "age16"
        case .age18:
            return "age18"
        case .age21:
            return "age21"
        case .cert:
            return "cert"
        case .doc:
            return "doc"
        case .pass:
            return "pass"
        case .sig:
            return "sig"
        @unknown default:
            return "unknown"
        }
    }
}


extension WebIdIosSdk.EUserActionIdentState {
    var stringValue: String {
        switch self {
        case .agentEditing:
            return "agentEditing"
        case .autoIdentPending:
            return "autoIdentPending"
        case .canceled:
            return "canceled"
        case .echeckPending:
            return "echeckPending"
        case .eidPendingAuthada:
            return "eidPendingAuthada"
        case .expired:
            return "expired"
        case .legalTermsConfirmationRequired:
            return "legalTermsConfirmationRequired"
        case .notSupported:
            return "notSupported"
        case .precheckPending:
            return "precheckPending"
        case .successful:
            return "successful"
        case .tanPending:
            return "tanPending"
        case .trueidPending:
            return "trueidPending"
        case .unsuccessful:
            return "unsuccessful"
        case .videocallPending:
            return "videocallPending"
        @unknown default:
            return "unknown"
        }
    }
}


extension WebIdIosSdk.EUserActionQesState {
    var stringValue: String {
        switch self {
        case .canceled:
            return "canceled"
        case .documentMissing:
            return "documentMissing"
        case .expired:
            return "expired"
        case .notApplicable:
            return "notApplicable"
        case .pending:
            return "pending"
        case .successful:
            return "successful"
        @unknown default:
            return "unknown"
        }
    }
}

extension WebIdIosSdk.EUserActionTanState {
    var stringValue: String {
        switch self {
        case .expired:
            return "expired"
        case .setAndUnverified:
            return "setAndUnverified"
        case .setAndVerified:
            return "setAndVerified"
        case .unset:
            return "unset"
        @unknown default:
            return "unknown"
        }
    }
}

extension EProduct {
    var stringValue: String {
        switch self {
        case .autoIdentOnServer:
            return "autoIdentOnServer"
        case .payIdentOnServer:
            return "payIdentOnServer"
        case .signIdDirectOnServer:
            return "signIdDirectOnServer"
        case .videoIdent:
            return "videoIdent"
        @unknown default:
            return "unknown"
        }
    }
}

extension EVideoIdentProductPluginFailReasons {
    var stringValue: String {
        switch self {            
//        case .missingParentViewController:
//            return "missingParentViewController"
        case .initFailed(_):
            return "initFailed"
        case .documentSigningNotPossible(_):
            return "documentSigningNotPossible"
        case .documentSigningSessionExpired(_):
            return "documentSigningSessionExpired"
        case .documentLoadUnsignedDocumentsFailure(_):
            return "documentLoadUnsignedDocumentsFailure"
//        case .documentSigningNotAllowed(_):
//            return "documentSigningNotAllowed"
//        case .jointUserActionLocked(_):
//            return "jointUserActionLocked"
        case .invalidDownloadToken(_):
            return "invalidDownloadToken"
        case .signedDocumentsDownloadNotPossible(_):
            return "signedDocumentsDownloadNotPossible"
        case .callCenterClosed(_):
            return "callCenterClosed"
        case .callInfoExpired(_):
            return "callInfoExpired"
        case .security(_):
            return "security"
        case .agentRejected(_):
            return "agentRejected"
        case .appointmentMade(_):
            return "appointmentMade"
        case .callInitializationFailed(_):
            return "callInitializationFailed"
        case .legalTermsConfirmationRequired:
            return "legalTermsConfirmationRequired"
        case .tanDeliveryFailed(_):
            return "tanDeliveryFailed"
        @unknown default:
            return "unknown"
        }
    }
}



