<commit_before>package peergos.shared.storage;

import jsinterop.annotations.*;
import peergos.shared.cbor.*;

import java.util.*;

public final class PaymentProperties  implements Cborable {

    public final Optional<String> paymentServerUrl;
    public final Optional<String> clientSecret;
    public final long freeQuota;
    public final long desiredQuota;

    private PaymentProperties(Optional<String> paymentServerUrl, Optional<String> clientSecret, long freeQuota, long desiredQuota) {
        this.paymentServerUrl = paymentServerUrl;
        this.clientSecret = clientSecret;
        this.freeQuota = freeQuota;
        this.desiredQuota = desiredQuota;
    }

    public PaymentProperties(long freeQuota) {
        this(Optional.empty(), Optional.empty(), freeQuota, 0);
    }

    public PaymentProperties(String paymentServerUrl, Optional<String> clientSecret, long freeQuota, long desiredQuota) {
        this(Optional.of(paymentServerUrl), clientSecret, freeQuota, desiredQuota);
    }

    @JsMethod
    public boolean isPaid() {
        return paymentServerUrl.isPresent();
    }

    @JsMethod
    public String getUrl() {
        return paymentServerUrl.get();
    }

    @JsMethod
    public String getClientSecret() {
        return clientSecret.orElse("");
    }

    @Override
    public CborObject toCbor() {
        SortedMap<String, Cborable> state = new TreeMap<>();
        state.put("freeQuota", new CborObject.CborLong(desiredQuota));
        state.put("desiredQuota", new CborObject.CborLong(desiredQuota));
        paymentServerUrl.ifPresent(url -> state.put("url", new CborObject.CborString(url)));
        if (clientSecret.isPresent())
            state.put("client_secret", new CborObject.CborString(clientSecret.get()));
        return CborObject.CborMap.build(state);
    }

    public static PaymentProperties fromCbor(Cborable cbor) {
        if (! (cbor instanceof CborObject.CborMap))
            throw new IllegalStateException("Invalid cbor for FileProperties! " + cbor);
        CborObject.CborMap m = (CborObject.CborMap) cbor;
        Optional<String> url = m.getOptional("url", c -> ((CborObject.CborString)c).value);
        Optional<String> client_secret = m.getOptional("client_secret", c -> ((CborObject.CborString) c).value);
        long freeQuota = m.getLong("freeQuota");
        long desiredQuota = m.getLong("desiredQuota");
        return new PaymentProperties(url, client_secret, freeQuota, desiredQuota);
    }
}<commit_msg>Add error to payment properties<commit_after>package peergos.shared.storage;

import jsinterop.annotations.*;
import peergos.shared.cbor.*;

import java.util.*;

public final class PaymentProperties  implements Cborable {

    public final Optional<String> paymentServerUrl;
    public final Optional<String> clientSecret;
    public final Optional<String> error;
    public final long freeQuota;
    public final long desiredQuota;

    private PaymentProperties(Optional<String> paymentServerUrl,
                              Optional<String> error,
                              Optional<String> clientSecret,
                              long freeQuota,
                              long desiredQuota) {
        this.paymentServerUrl = paymentServerUrl;
        this.error = error;
        this.clientSecret = clientSecret;
        this.freeQuota = freeQuota;
        this.desiredQuota = desiredQuota;
    }

    public PaymentProperties(long freeQuota) {
        this(Optional.empty(), Optional.empty(), Optional.empty(), freeQuota, 0);
    }

    public PaymentProperties(String paymentServerUrl, Optional<String> clientSecret, long freeQuota, long desiredQuota) {
        this(Optional.of(paymentServerUrl), Optional.empty(), clientSecret, freeQuota, desiredQuota);
    }

    @JsMethod
    public boolean isPaid() {
        return paymentServerUrl.isPresent();
    }

    @JsMethod
    public boolean hasError() {
        return error.isPresent();
    }

    @JsMethod
    public String getError() {
        return error.get();
    }

    @JsMethod
    public String getUrl() {
        return paymentServerUrl.get();
    }

    @JsMethod
    public String getClientSecret() {
        return clientSecret.orElse("");
    }

    public static PaymentProperties errored(String paymentServerUrl,
                                            String error,
                                            Optional<String> clientSecret,
                                            long freeQuota,
                                            long desiredQuota) {
        return new PaymentProperties(Optional.of(paymentServerUrl), Optional.of(error), clientSecret, freeQuota, desiredQuota);
    }

    @Override
    public CborObject toCbor() {
        SortedMap<String, Cborable> state = new TreeMap<>();
        state.put("freeQuota", new CborObject.CborLong(desiredQuota));
        state.put("desiredQuota", new CborObject.CborLong(desiredQuota));
        paymentServerUrl.ifPresent(url -> state.put("url", new CborObject.CborString(url)));
        error.ifPresent(err -> state.put("err", new CborObject.CborString(err)));
        if (clientSecret.isPresent())
            state.put("client_secret", new CborObject.CborString(clientSecret.get()));
        return CborObject.CborMap.build(state);
    }

    public static PaymentProperties fromCbor(Cborable cbor) {
        if (! (cbor instanceof CborObject.CborMap))
            throw new IllegalStateException("Invalid cbor for FileProperties! " + cbor);
        CborObject.CborMap m = (CborObject.CborMap) cbor;
        Optional<String> url = m.getOptional("url", c -> ((CborObject.CborString)c).value);
        Optional<String> err = m.getOptional("err", c -> ((CborObject.CborString)c).value);
        Optional<String> client_secret = m.getOptional("client_secret", c -> ((CborObject.CborString) c).value);
        long freeQuota = m.getLong("freeQuota");
        long desiredQuota = m.getLong("desiredQuota");
        return new PaymentProperties(url, err, client_secret, freeQuota, desiredQuota);
    }
}
{'fraction_non_alphanumeric': 0.10319166528857285, 'fraction_numerical': 0.000330742516950554, 'mean_word_length': 2.904454486765655, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '669607', 'n_tokens_mistral': 1668, 'n_tokens_neox': 1644, 'n_words': 364}