package org.wikipedia.dataclient.mwapi;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArraySet;

import org.wikipedia.util.DateUtil;

import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("unused")
public class UserInfo {
    private String name;
    private int id;
    @Nullable private List<String> groups;
    private int blockid;
    @Nullable private String blockreason;
    @Nullable private String blockedby;
    @Nullable private String blockedtimestamp;
    @Nullable private String blockexpiry;

    // Object type is any JSON type.
    @Nullable private Map<String, ?> options;

    public int id() {
        return id;
    }

    @NonNull public Set<String> getGroups() {
        return groups != null ? new ArraySet<>(groups) : Collections.emptySet();
    }

    public boolean isBlocked() {
        if (TextUtils.isEmpty(blockexpiry)) {
            return false;
        }
        try {
            Date now = new Date();
            Date expiry = DateUtil.iso8601DateParse(blockexpiry);
            if (expiry.after(now)) {
                return true;
            }
        } catch (ParseException e) {
            // ignore
        }
        return false;
    }

    @NonNull public Map<String, String> userjsOptions() {
        Map<String, String> map = new HashMap<>();
        if (options != null) {
            for (Map.Entry<String, ?> entry : options.entrySet()) {
                if (entry.getKey().startsWith("userjs-")) {
                    // T161866 entry.valueOf() should always return a String but doesn't
                    map.put(entry.getKey(), entry.getValue() == null ? "" : String.valueOf(entry.getValue()));
                }
            }
        }
        return map;
    }
}

@@ -1407,544 +1407,7 @@
    %7D
-%0A%0A    @NonNull public Map%3CString, String%3E userjsOptions() %7B%0A        Map%3CString, String%3E map = new HashMap%3C%3E();%0A        if (options != null) %7B%0A            for (Map.Entry%3CString, ?%3E entry : options.entrySet()) %7B%0A                if (entry.getKey().startsWith(%22userjs-%22)) %7B%0A                    // T161866 entry.valueOf() should always return a String but doesn't%0A                    map.put(entry.getKey(), entry.getValue() == null ? %22%22 : String.valueOf(entry.getValue()));%0A                %7D%0A            %7D%0A        %7D%0A        return map;%0A    %7D
 %0A%7D%0A

Remove unused userjsOptions