import Foundation

extension ClientState {
    static func reducer(state: inout ClientState, action: ClientAction) {
        switch action {
        case .empty:
            break

        case .clientError(let error):
            state.lastError = error

        case .connectionAction(let action):
            ConnectionState.reducer(state: &state.connectionState, action: action)

        case .parserAction:
            break

        case .streamAction(let action):
            StreamState.reducer(state: &state.streamState, action: action)

        case .authAction(let action):
            AuthState.reducer(state: &state.authState, action: action)

        case .bindResourceAction(let action):
            switch action {
            case .updateJid(let newJid):
                state.jid = newJid

            default:
                break
            }

        case .externalServiceAction(let action):
            ExternalServicesState.reducer(state: &state.externalServicesState, action: action)

        case .callAction(let action):
            CallState.reducer(state: &state.callState, action: action)
        }
    }
}
