// Path: src/main/java/com/amazon/dtasdk/v3/serialization/messages/GetUserIdSerializableRequest.java
// public class GetUserIdSerializableRequest extends com.amazon.dtasdk.v2.serialization.messages.GetUserIdSerializableRequest {
// }
// 
// Path: src/main/java/com/amazon/dtasdk/v3/serialization/messages/GetUserIdSerializableResponse.java
// public class GetUserIdSerializableResponse extends com.amazon.dtasdk.v2.serialization.messages.GetUserIdSerializableResponse {
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessOperationValue.java
// public enum InstantAccessOperationValue {
//     PURCHASE("Purchase"),
//     REVOKE("Revoke"),
//     GETUSERID("GetUserId"),
//     SUBSCRIPTIONGET("SubscriptionGet"),
//     SUBSCRIPTIONACTIVATE("SubscriptionActivate"),
//     SUBSCRIPTIONDEACTIVATE("SubscriptionDeactivate"),
//     SUBSCRIPTIONUPDATE("SubscriptionUpdate");
// 
//     private String apiName;
// 
//     /**
//      * @param apiName
//      *            The string representation of the operation according to the API
//      */
//     InstantAccessOperationValue(String apiName) {
//         this.apiName = apiName;
//     }
// 
//     @JsonValue
//     public String toJson() {
//         return apiName;
//     }
// 
//     @JsonCreator
//     public static InstantAccessOperationValue fromJson(String text) {
//         // ignore the case when deserializing
//         return valueOf(text.toUpperCase());
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessResponse.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
// public abstract class InstantAccessResponse<R extends Serializable> {
//     protected R response;
// 
//     public R getResponse() {
//         return response;
//     }
// 
//     public void setResponse(R response) {
//         this.response = response;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((response == null) ? 0 : response.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null) {
//             return false;
//         }
//         if (getClass() != obj.getClass()) {
//             return false;
//         }
//         InstantAccessResponse other = (InstantAccessResponse) obj;
//         if (response == null) {
//             if (other.response != null) {
//                 return false;
//             }
//         } else if (!response.equals(other.response)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("response", response).toString();
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/serializer/SerializationException.java
// public class SerializationException extends Exception {
//     private static final long serialVersionUID = -3095196341869438153L;
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


import com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableRequest;
import com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableResponse;
import com.amazon.dtasdk.base.InstantAccessOperationValue;
import com.amazon.dtasdk.base.InstantAccessResponse;
import com.amazon.dtasdk.serializer.SerializationException;
/*
 * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazon.dtasdk.v3.servlets;


/**
 * <p>
 * This abstract servlet can be extended to implement the V3 Account Linking section of Instant Access API.
 * </p>
 *
 * <p>
 * When extending this servlet, you must implement the abstract method {@link #getUserId( GetUserIdSerializableRequest )},
 * it is the method for returning a user id based on the parameters in order to link accounts.
 * </p>
 *
 * <p>
 * You must also implement the abstract method {@link #getCredentialStore()}. This method must provide a valid credential
 * store that will be used to verify the message authenticity.
 * </p>
 *
 */
public abstract class AccountLinkingServlet extends InstantAccessServlet {

    /**
     * Process the request and returns the user id
     *
     * @param request
     *            the request relative to the get user id operation
     *
     * @return a GetUserIdSerializableResponse object
     */
    public abstract GetUserIdSerializableResponse getUserId(GetUserIdSerializableRequest request);

    @Override
    public InstantAccessResponse<?> processOperation(InstantAccessOperationValue operation, String requestBody)
            throws SerializationException {

        GetUserIdSerializableResponse iaResponse;

        // process the request according to the operation
        switch (operation) {
            case GETUSERID:
                iaResponse = getUserId(serializer.decode(requestBody, GetUserIdSerializableRequest.class));
// Path: src/main/java/com/amazon/dtasdk/v3/serialization/messages/GetUserIdSerializableRequest.java
// public class GetUserIdSerializableRequest extends com.amazon.dtasdk.v2.serialization.messages.GetUserIdSerializableRequest {
// }
// 
// Path: src/main/java/com/amazon/dtasdk/v3/serialization/messages/GetUserIdSerializableResponse.java
// public class GetUserIdSerializableResponse extends com.amazon.dtasdk.v2.serialization.messages.GetUserIdSerializableResponse {
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessOperationValue.java
// public enum InstantAccessOperationValue {
//     PURCHASE("Purchase"),
//     REVOKE("Revoke"),
//     GETUSERID("GetUserId"),
//     SUBSCRIPTIONGET("SubscriptionGet"),
//     SUBSCRIPTIONACTIVATE("SubscriptionActivate"),
//     SUBSCRIPTIONDEACTIVATE("SubscriptionDeactivate"),
//     SUBSCRIPTIONUPDATE("SubscriptionUpdate");
// 
//     private String apiName;
// 
//     /**
//      * @param apiName
//      *            The string representation of the operation according to the API
//      */
//     InstantAccessOperationValue(String apiName) {
//         this.apiName = apiName;
//     }
// 
//     @JsonValue
//     public String toJson() {
//         return apiName;
//     }
// 
//     @JsonCreator
//     public static InstantAccessOperationValue fromJson(String text) {
//         // ignore the case when deserializing
//         return valueOf(text.toUpperCase());
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/base/InstantAccessResponse.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
// public abstract class InstantAccessResponse<R extends Serializable> {
//     protected R response;
// 
//     public R getResponse() {
//         return response;
//     }
// 
//     public void setResponse(R response) {
//         this.response = response;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         result = prime * result + ((response == null) ? 0 : response.hashCode());
//         return result;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         }
//         if (obj == null) {
//             return false;
//         }
//         if (getClass() != obj.getClass()) {
//             return false;
//         }
//         InstantAccessResponse other = (InstantAccessResponse) obj;
//         if (response == null) {
//             if (other.response != null) {
//                 return false;
//             }
//         } else if (!response.equals(other.response)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public String toString() {
//         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("response", response).toString();
//     }
// }
// 
// Path: src/main/java/com/amazon/dtasdk/serializer/SerializationException.java
// public class SerializationException extends Exception {
//     private static final long serialVersionUID = -3095196341869438153L;
// 
//     public SerializationException(String message) {
//         super(message);
//     }
// 
//     public SerializationException(Throwable cause) {
//         super(cause);
//     }
// 
//     public SerializationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// }


// Path: src/main/java/com/amazon/dtasdk/v3/servlets/AccountLinkingServlet.java
import com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableRequest;
import com.amazon.dtasdk.v3.serialization.messages.GetUserIdSerializableResponse;
import com.amazon.dtasdk.base.InstantAccessOperationValue;
import com.amazon.dtasdk.base.InstantAccessResponse;
import com.amazon.dtasdk.serializer.SerializationException;

/*
 * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */
package com.amazon.dtasdk.v3.servlets;


/**
 * <p>
 * This abstract servlet can be extended to implement the V3 Account Linking section of Instant Access API.
 * </p>
 *
 * <p>
 * When extending this servlet, you must implement the abstract method {@link #getUserId( GetUserIdSerializableRequest )},
 * it is the method for returning a user id based on the parameters in order to link accounts.
 * </p>
 *
 * <p>
 * You must also implement the abstract method {@link #getCredentialStore()}. This method must provide a valid credential
 * store that will be used to verify the message authenticity.
 * </p>
 *
 */
public abstract class AccountLinkingServlet extends InstantAccessServlet {

    /**
     * Process the request and returns the user id
     *
     * @param request
     *            the request relative to the get user id operation
     *
     * @return a GetUserIdSerializableResponse object
     */
    public abstract GetUserIdSerializableResponse getUserId(GetUserIdSerializableRequest request);

    @Override
    public InstantAccessResponse<?> processOperation(InstantAccessOperationValue operation, String requestBody)
            throws SerializationException {

        GetUserIdSerializableResponse iaResponse;

        // process the request according to the operation
        switch (operation) {
            case GETUSERID:
                iaResponse = getUserId(serializer.decode(requestBody, GetUserIdSerializableRequest.class));
            break;