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

app.knock.api.model.CreateSchedulesRequest Maven / Gradle / Ivy

package app.knock.api.model;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Singular;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;

import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Value
@Jacksonized
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class CreateSchedulesRequest {

    @JsonProperty("__typename")
    String typeName;

    String workflow;
    List recipients;
    List repeats;
    Object actor;
    Object tenant;
    ZonedDateTime scheduledAt;

    @Singular("data")
    @JsonAnySetter
    Map data;

    public  T data(String key, Class clazz) {
        if (this.data != null && this.data.containsKey(key)) {
            Object o = this.data.get(key);
            return clazz.isInstance(o) ? clazz.cast(o) : null;
        }
        return null;
    }

    public static class CreateSchedulesRequestBuilder {

        List recipients;

        public CreateSchedulesRequestBuilder addActor(ObjectRecipientIdentifier identifier) {
            this.actor = identifier;
            return this;
        }

        public CreateSchedulesRequestBuilder addActor(String actor) {
            this.actor = actor;
            return this;
        }

        public CreateSchedulesRequestBuilder addActor(Map actor) {
            this.actor = actor;
            return this;
        }

        public CreateSchedulesRequestBuilder addTenant(String tenant) {
            this.tenant = tenant;
            return this;
        }

        public CreateSchedulesRequestBuilder addTenant(Map tenant) {
            this.tenant = tenant;
            return this;
        }

        public CreateSchedulesRequestBuilder addRecipient(String... userIds) {
            if (this.recipients == null) { this.recipients = new ArrayList<>(); }
            Collections.addAll(this.recipients, userIds);
            return this;
        }

        public CreateSchedulesRequestBuilder addRecipient(Map recipient) {
            if (this.recipients == null) { this.recipients = new ArrayList<>(); }
            Collections.addAll(this.recipients, recipient);
            return this;
        }

        public CreateSchedulesRequestBuilder addRecipient(ObjectRecipientIdentifier identifier) {
            if (this.recipients == null) { this.recipients = new ArrayList<>(); }
            Collections.addAll(this.recipients, identifier);
            return this;
        }

        public CreateSchedulesRequestBuilder addRepeat(ScheduleRepeat repeat) {
            if (this.repeats == null) { this.repeats = new ArrayList<>(); }
            Collections.addAll(this.repeats, repeat);
            return this;
        }
    }
}