// Path: src/main/java/org/killbill/billing/plugin/simpletax/config/http/CustomFieldService.java
// public static final String VATIN_CUSTOM_FIELD_NAME = "VATIdNum";
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/internal/VATIN.java
// public class VATIN {
// 
//     private static final VATINValidator VALIDATOR = new VATINValidator();
// 
//     private String number;
// 
//     /**
//      * @param number
//      *            A valid VAT Identificaiton Number.
//      * @throws IllegalArgumentException
//      *             When the VAT number is invalid.
//      */
//     @JsonCreator
//     public VATIN(String number) throws IllegalArgumentException {
//         super();
//         checkArgument(VALIDATOR.apply(number), "Illegal VAT Identification Number: [%s]", number);
//         this.number = number;
//     }
// 
//     /**
//      * @return The VAT Identificaiton Number.
//      */
//     @JsonValue
//     public String getNumber() {
//         return number;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         if (obj.getClass() != getClass()) {
//             return false;
//         }
//         VATIN rhs = (VATIN) obj;
//         return new EqualsBuilder().append(number, rhs.number).isEquals();
//     }
// 
//     @Override
//     public int hashCode() {
//         return new HashCodeBuilder().append(number).toHashCode();
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, SHORT_STYLE)//
//                 .append("number", number)//
//                 .toString();
//     }
// }


import org.killbill.billing.util.customfield.CustomField;
import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillLogService;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import static com.google.common.collect.Lists.newArrayList;
import static org.killbill.billing.plugin.simpletax.config.http.CustomFieldService.VATIN_CUSTOM_FIELD_NAME;
import static org.osgi.service.log.LogService.LOG_ERROR;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.killbill.billing.plugin.api.PluginTenantContext;
import org.killbill.billing.plugin.simpletax.internal.VATIN;
import org.killbill.billing.tenant.api.Tenant;
import org.killbill.billing.util.callcontext.TenantContext;
                accountId, tenantContext);
        if (field == null) {
            return null;
        }
        return toVATINJsonOrNull(accountId, field.getFieldValue());
    }

    /**
     * Persists a new VAT Identification Number value for a given account.
     *
     * @param accountId
     *            An account the VAT Identification Number of which should be
     *            modified. Must not be {@code null}.
     * @param vatinRsc
     *            A new VAT Identification Number resource to persist. Must not
     *            be {@code null}.
     * @param tenant
     *            The tenant on which to operate.
     * @return {@code true} if the VAT Identification Number is properly saved,
     *         or {@code false} otherwise.
     * @throws NullPointerException
     *             When {@code vatinRsc} is {@code null}.
     */
    public boolean saveAccountVatin(@Nonnull UUID accountId, @Nonnull VATINRsc vatinRsc, Tenant tenant) {
        TenantContext tenantContext = new PluginTenantContext(tenant.getId());
        String newValue = vatinRsc.vatin.getNumber();
        return customFieldService.saveAccountField(newValue, VATIN_CUSTOM_FIELD_NAME, accountId, tenantContext);
    }

    private VATINRsc toVATINJsonOrNull(UUID accountId, String vatin) {
// Path: src/main/java/org/killbill/billing/plugin/simpletax/config/http/CustomFieldService.java
// public static final String VATIN_CUSTOM_FIELD_NAME = "VATIdNum";
// 
// Path: src/main/java/org/killbill/billing/plugin/simpletax/internal/VATIN.java
// public class VATIN {
// 
//     private static final VATINValidator VALIDATOR = new VATINValidator();
// 
//     private String number;
// 
//     /**
//      * @param number
//      *            A valid VAT Identificaiton Number.
//      * @throws IllegalArgumentException
//      *             When the VAT number is invalid.
//      */
//     @JsonCreator
//     public VATIN(String number) throws IllegalArgumentException {
//         super();
//         checkArgument(VALIDATOR.apply(number), "Illegal VAT Identification Number: [%s]", number);
//         this.number = number;
//     }
// 
//     /**
//      * @return The VAT Identificaiton Number.
//      */
//     @JsonValue
//     public String getNumber() {
//         return number;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (obj == null) {
//             return false;
//         }
//         if (obj == this) {
//             return true;
//         }
//         if (obj.getClass() != getClass()) {
//             return false;
//         }
//         VATIN rhs = (VATIN) obj;
//         return new EqualsBuilder().append(number, rhs.number).isEquals();
//     }
// 
//     @Override
//     public int hashCode() {
//         return new HashCodeBuilder().append(number).toHashCode();
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, SHORT_STYLE)//
//                 .append("number", number)//
//                 .toString();
//     }
// }


// Path: src/main/java/org/killbill/billing/plugin/simpletax/config/http/VatinController.java
import org.killbill.billing.util.customfield.CustomField;
import org.killbill.killbill.osgi.libs.killbill.OSGIKillbillLogService;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import static com.google.common.collect.Lists.newArrayList;
import static org.killbill.billing.plugin.simpletax.config.http.CustomFieldService.VATIN_CUSTOM_FIELD_NAME;
import static org.osgi.service.log.LogService.LOG_ERROR;
import java.util.List;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.killbill.billing.plugin.api.PluginTenantContext;
import org.killbill.billing.plugin.simpletax.internal.VATIN;
import org.killbill.billing.tenant.api.Tenant;
import org.killbill.billing.util.callcontext.TenantContext;

                accountId, tenantContext);
        if (field == null) {
            return null;
        }
        return toVATINJsonOrNull(accountId, field.getFieldValue());
    }

    /**
     * Persists a new VAT Identification Number value for a given account.
     *
     * @param accountId
     *            An account the VAT Identification Number of which should be
     *            modified. Must not be {@code null}.
     * @param vatinRsc
     *            A new VAT Identification Number resource to persist. Must not
     *            be {@code null}.
     * @param tenant
     *            The tenant on which to operate.
     * @return {@code true} if the VAT Identification Number is properly saved,
     *         or {@code false} otherwise.
     * @throws NullPointerException
     *             When {@code vatinRsc} is {@code null}.
     */
    public boolean saveAccountVatin(@Nonnull UUID accountId, @Nonnull VATINRsc vatinRsc, Tenant tenant) {
        TenantContext tenantContext = new PluginTenantContext(tenant.getId());
        String newValue = vatinRsc.vatin.getNumber();
        return customFieldService.saveAccountField(newValue, VATIN_CUSTOM_FIELD_NAME, accountId, tenantContext);
    }

    private VATINRsc toVATINJsonOrNull(UUID accountId, String vatin) {
        VATIN vatinObj;