001/*
002 * Copyright (c) 2011-2018 Nexmo Inc
003 *
004 * Permission is hereby granted, free of charge, to any person obtaining a copy
005 * of this software and associated documentation files (the "Software"), to deal
006 * in the Software without restriction, including without limitation the rights
007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008 * copies of the Software, and to permit persons to whom the Software is
009 * furnished to do so, subject to the following conditions:
010 *
011 * The above copyright notice and this permission notice shall be included in
012 * all copies or substantial portions of the Software.
013 *
014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
020 * THE SOFTWARE.
021 */
022package com.nexmo.client.redact;
023
024import com.fasterxml.jackson.annotation.JsonInclude;
025import com.fasterxml.jackson.annotation.JsonValue;
026import com.fasterxml.jackson.core.JsonProcessingException;
027import com.fasterxml.jackson.databind.ObjectMapper;
028import com.nexmo.client.NexmoUnexpectedException;
029
030/**
031 * Represents a request to the Redact API.
032 */
033@JsonInclude(JsonInclude.Include.NON_NULL)
034public class RedactRequest {
035
036    private String id;
037    private Product product;
038    private Type type;
039
040    /**
041     * Construct a RedactRequest object with all required fields.
042     *
043     * @param id      The transaction id to redact.
044     * @param product The {@link Product} that the id relates to.
045     */
046    public RedactRequest(String id, Product product) {
047        this.id = id;
048        this.product = product;
049    }
050
051    public String getId() {
052        return id;
053    }
054
055    public void setId(String id) {
056        this.id = id;
057    }
058
059    public Product getProduct() {
060        return product;
061    }
062
063    public void setProduct(Product product) {
064        this.product = product;
065    }
066
067    public Type getType() {
068        return type;
069    }
070
071    public void setType(Type type) {
072        this.type = type;
073    }
074
075    public String toJson() {
076        try {
077            ObjectMapper mapper = new ObjectMapper();
078            return mapper.writeValueAsString(this);
079        } catch (JsonProcessingException jpe) {
080            throw new NexmoUnexpectedException("Failed to produce json from RedactRequest object.", jpe);
081        }
082    }
083
084    public enum Product {
085        SMS("sms"),
086        VOICE("voice"),
087        NUMBER_INSIGHTS("number-insight"),
088        VERIFY("verify"),
089        VERIFY_SDK("verify-sdk"),
090        /**
091         * @deprecated Use {@link Product#MESSAGES}
092         **/
093        @Deprecated MESSAGE("messages"),
094        MESSAGES("messages"),
095        WORKFLOW("workflow");
096
097        private String value;
098
099        Product(String value) {
100            this.value = value;
101        }
102
103        @JsonValue
104        public String getValue() {
105            return value;
106        }
107    }
108
109    public enum Type {
110        INBOUND, OUTBOUND;
111
112        @JsonValue
113        public String getValue() {
114            return this.name().toLowerCase();
115        }
116    }
117}