package net.alexyu.model;

import net.alexyu.common.pubsub.DataId;
import net.alexyu.common.pubsub.SubscriptionKey;

/**
 * Created by alex on 3/23/17.
 */
public class InterestRateId implements DataId<InterestRate>, SubscriptionKey<InterestRate> {

    public final String ccyId;

    public InterestRateId(String ccyId) {
        this.ccyId = ccyId;
    }

    public InterestRateId(Instrument instrument) {
        this.ccyId = instrument.getCcyId();
    }

    public InterestRateId(InterestRate interestRate) {
        this.ccyId = interestRate.getCcyId();
    }

    public static InterestRateId of(String ccyId) {
        return new InterestRateId(ccyId);
    }

    public static InterestRateId of(Instrument instrument) {
        return new InterestRateId(instrument);
    }


    public static InterestRateId of(InterestRate interestRate) {
        return new InterestRateId(interestRate);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        InterestRateId that = (InterestRateId) o;

        return ccyId != null ? ccyId.equals(that.ccyId) : that.ccyId == null;
    }

    @Override
    public int hashCode() {
        return ccyId != null ? ccyId.hashCode() : 0;
    }

    @Override
    public String toString() {
        return "InterestRateId{" +
                "ccyId='" + ccyId + '\'' +
                '}';
    }

    @Override
    public boolean test(DataId<InterestRate> dataId) {
        return equals(dataId);
    }

    @Override
    public String id() {
        return ccyId;
    }
}
