package lc.esp.eo;

import lc.esp.eo.sdk.schema.Model;

import java.util.Objects;

/**
 * Classes extending {@link EOBased} provided services which are backed by an EO LPAR. Generic functionality is provided
 * for linking the services to a particular LPAR and providing transactional book-keeping.
 *
 * @author Alex Leigh
 * @since mk20 (TOKYO PROTOCOL)
 */
public class EOBased {
    private final EOClient client = new EOClient();
    private final String lpar;

    public EOBased(String lpar) {
        this.lpar = lpar;
    }

    public EOClient getClient() {
        return client;
    }

    public EOTransaction getTransaction() {
        return client.getTransaction(lpar);
    }

    public EOTransaction getTransaction(Model model) {
        return client.getTransaction(lpar, model);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        EOBased eoBased = (EOBased) o;
        return Objects.equals(lpar, eoBased.lpar);
    }

    @Override
    public int hashCode() {
        return Objects.hash(lpar);
    }

    @Override
    public String toString() {
        return "EOBased{" +
                "client=" + client +
                ", lpar='" + lpar + '\'' +
                '}';
    }
}
