All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sinch.sdk.domains.sms.models.requests.UpdateBaseBatchRequest Maven / Gradle / Ivy

There is a newer version: 1.4.0
Show newest version
package com.sinch.sdk.domains.sms.models.requests;

import com.sinch.sdk.core.models.OptionalValue;
import com.sinch.sdk.domains.sms.models.DeliveryReportType;
import java.time.Instant;
import java.util.Collection;

/**
 * Base class for Batch types
 *
 * @param  Type of batch
 * @since 1.0
 */
public class UpdateBaseBatchRequest {

  private final OptionalValue from;

  private final OptionalValue body;

  private final OptionalValue> toAdd;

  private final OptionalValue> toRemove;

  private final OptionalValue deliveryReport;

  private final OptionalValue sendAt;

  private final OptionalValue expireAt;

  private final OptionalValue callbackUrl;

  protected UpdateBaseBatchRequest(
      OptionalValue> toAdd,
      OptionalValue> toRemove,
      OptionalValue from,
      OptionalValue body,
      OptionalValue deliveryReport,
      OptionalValue sendAt,
      OptionalValue expireAt,
      OptionalValue callbackUrl) {
    this.toAdd = toAdd;
    this.toRemove = toRemove;
    this.from = from;
    this.body = body;
    this.deliveryReport = deliveryReport;
    this.sendAt = sendAt;
    this.expireAt = expireAt;
    this.callbackUrl = callbackUrl;
  }

  public static  BatchBuilder batchBuilder() {
    return new BatchBuilder<>();
  }

  public OptionalValue> getToAdd() {
    return toAdd;
  }

  public OptionalValue> getToRemove() {
    return toRemove;
  }

  public OptionalValue getBody() {
    return body;
  }

  public OptionalValue getFrom() {
    return from;
  }

  public OptionalValue getDeliveryReport() {
    return deliveryReport;
  }

  public OptionalValue getSendAt() {
    return sendAt;
  }

  public OptionalValue getExpireAt() {
    return expireAt;
  }

  public OptionalValue getCallbackUrl() {
    return callbackUrl;
  }

  @Override
  public String toString() {
    return "UpdateBaseBatchRequest{"
        + "from='"
        + from
        + '\''
        + ", body="
        + body
        + ", toAdd="
        + toAdd
        + ", toRemove="
        + toRemove
        + ", deliveryReportType="
        + deliveryReport
        + ", sendAt="
        + sendAt
        + ", expireAt="
        + expireAt
        + ", callbackUrl='"
        + callbackUrl
        + '\''
        + '}';
  }

  protected static class Builder> {

    public OptionalValue> toAdd = OptionalValue.empty();

    public OptionalValue> toRemove = OptionalValue.empty();

    public OptionalValue from = OptionalValue.empty();

    public OptionalValue body = OptionalValue.empty();

    public OptionalValue deliveryReportType = OptionalValue.empty();

    public OptionalValue sendAt = OptionalValue.empty();

    public OptionalValue expireAt = OptionalValue.empty();

    public OptionalValue callbackUrl = OptionalValue.empty();

    /**
     * @param toAdd List of phone numbers and group IDs to add to the batch.
     * @return current builder
     */
    public B setToAdd(Collection toAdd) {
      this.toAdd = OptionalValue.of(toAdd);
      return self();
    }

    /**
     * @param toRemove List of phone numbers and group IDs to remove from the batch.
     * @return current builder
     */
    public B setToRemove(Collection toRemove) {
      this.toRemove = OptionalValue.of(toRemove);
      return self();
    }

    /**
     * @param from Sender number. Must be valid phone number, short code or alphanumeric. Required
     *     if Automatic Default Originator not configured.
     * @return current builder
     */
    public B setFrom(String from) {
      this.from = OptionalValue.of(from);
      return self();
    }

    /**
     * @param body The message content
     * @return current builder
     */
    public B setBody(T body) {
      this.body = OptionalValue.of(body);
      return self();
    }

    /**
     * @param deliveryReportType Request delivery report callback. Note that delivery reports can be
     *     fetched from the API regardless of this setting
     * @return current builder
     */
    public B setDeliveryReport(DeliveryReportType deliveryReportType) {
      this.deliveryReportType = OptionalValue.of(deliveryReportType);
      return self();
    }

    /**
     * @param sendAt If set in the future, the message will be delayed until send_at occurs. Must be
     *     before expire_at. If set in the past, messages will be sent immediately
     * @return current builder
     */
    public B setSendAt(Instant sendAt) {
      this.sendAt = OptionalValue.of(sendAt);
      return self();
    }

    /**
     * @param expireAt If set, the system will stop trying to deliver the message at this point.
     *     Must be after send_at. Default and max is 3 days after send_at
     * @return current builder
     */
    public B setExpireAt(Instant expireAt) {
      this.expireAt = OptionalValue.of(expireAt);
      return self();
    }

    /**
     * @param callbackUrl Override the default callback URL for this batch. Must be valid URL.
     * @return current builder
     */
    public B setCallbackUrl(String callbackUrl) {
      this.callbackUrl = OptionalValue.of(callbackUrl);
      return self();
    }

    public UpdateBaseBatchRequest build() {
      return new UpdateBaseBatchRequest<>(
          toAdd, toRemove, from, body, deliveryReportType, sendAt, expireAt, callbackUrl);
    }

    @SuppressWarnings("unchecked")
    protected B self() {
      return (B) this;
    }
  }

  public static class BatchBuilder extends UpdateBaseBatchRequest.Builder> {
    @Override
    protected BatchBuilder self() {
      return this;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy