Agent.java

package info.textgrid.services.textapi.apiv2;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * Represents an Agent (person or organization) in TextAPI v2.
 * Used for collectors, editors, funders, and other roles.
 */
@JsonPropertyOrder({
    "roles",
    "name",
    "id",
    "sameAs",
    "textapiType"
})
public class Agent {

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> roles = new ArrayList<>();

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String name;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String id;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<String> sameAs;

    @JsonProperty("textapiType")
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String textapiType = "TextApiAgent";

    /**
     * Required roles for this agent
     */
    public List<String> getRoles() {
        return roles;
    }

    public Agent setRoles(List<String> roles) {
        this.roles = roles;
        return this;
    }

    public Agent addRole(String role) {
        this.roles.add(role);
        return this;
    }

    /**
     * Required name of the agent
     */
    public String getName() {
        return name;
    }

    public Agent setName(String name) {
        this.name = name;
        return this;
    }

    /**
     * Optional internal identifier
     */
    public String getId() {
        return id;
    }

    public Agent setId(String id) {
        this.id = id;
        return this;
    }

    /**
     * Optional external identifiers
     */
    public List<String> getSameAs() {
        return sameAs;
    }

    public Agent setSameAs(List<String> sameAs) {
        this.sameAs = sameAs;
        return this;
    }

    public Agent addSameAs(String sameAs) {
        if (this.sameAs == null) {
            this.sameAs = new ArrayList<>();
        }
        this.sameAs.add(sameAs);
        return this;
    }

    /**
     * Must always be "TextApiAgent"
     */
    public String getTextapiType() {
        return textapiType;
    }

    public Agent setTextapiType(String textapiType) {
        this.textapiType = textapiType;
        return this;
    }
}