/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.core.marketdatasnapshot;

import java.util.Map;

import org.joda.beans.Bean;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectBean;
import org.joda.beans.impl.direct.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;

import com.opengamma.util.time.Tenor;

/**
 * A key which specifies a point in volatility space
 */
@BeanDefinition
public class VolatilityPoint extends DirectBean {

  /**
   * The swap tenor
   */
  @PropertyDefinition
  private Tenor _swapTenor;
  /**
   * The option expiry
   */
  @PropertyDefinition
  private Tenor _optionExpiry;
  /**
   * The strike relative to at the money, in Bps
   */
  @PropertyDefinition
  private double _relativeStrike;

  /**
   * Restricted constructor.
   */
  private VolatilityPoint() {
  }

  /**
   * Creates an instance.
   * 
   * @param swapTenor  the swap tenor
   * @param optionExpiry  the option expiry
   * @param relativeStrike  the relative strike
   */
  public VolatilityPoint(Tenor swapTenor, Tenor optionExpiry, double relativeStrike) {
    super();
    _swapTenor = swapTenor;
    _optionExpiry = optionExpiry;
    _relativeStrike = relativeStrike;
  }

  //------------------------- AUTOGENERATED START -------------------------
  ///CLOVER:OFF
  /**
   * The meta-bean for {@code VolatilityPoint}.
   * @return the meta-bean, not null
   */
  public static VolatilityPoint.Meta meta() {
    return VolatilityPoint.Meta.INSTANCE;
  }

  static {
    JodaBeanUtils.registerMetaBean(VolatilityPoint.Meta.INSTANCE);
  }

  @Override
  public VolatilityPoint.Meta metaBean() {
    return VolatilityPoint.Meta.INSTANCE;
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the swap tenor
   * @return the value of the property
   */
  public Tenor getSwapTenor() {
    return _swapTenor;
  }

  /**
   * Sets the swap tenor
   * @param swapTenor  the new value of the property
   */
  public void setSwapTenor(Tenor swapTenor) {
    this._swapTenor = swapTenor;
  }

  /**
   * Gets the the {@code swapTenor} property.
   * @return the property, not null
   */
  public final Property<Tenor> swapTenor() {
    return metaBean().swapTenor().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the option expiry
   * @return the value of the property
   */
  public Tenor getOptionExpiry() {
    return _optionExpiry;
  }

  /**
   * Sets the option expiry
   * @param optionExpiry  the new value of the property
   */
  public void setOptionExpiry(Tenor optionExpiry) {
    this._optionExpiry = optionExpiry;
  }

  /**
   * Gets the the {@code optionExpiry} property.
   * @return the property, not null
   */
  public final Property<Tenor> optionExpiry() {
    return metaBean().optionExpiry().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the strike relative to at the money, in Bps
   * @return the value of the property
   */
  public double getRelativeStrike() {
    return _relativeStrike;
  }

  /**
   * Sets the strike relative to at the money, in Bps
   * @param relativeStrike  the new value of the property
   */
  public void setRelativeStrike(double relativeStrike) {
    this._relativeStrike = relativeStrike;
  }

  /**
   * Gets the the {@code relativeStrike} property.
   * @return the property, not null
   */
  public final Property<Double> relativeStrike() {
    return metaBean().relativeStrike().createProperty(this);
  }

  //-----------------------------------------------------------------------
  @Override
  public VolatilityPoint clone() {
    return JodaBeanUtils.cloneAlways(this);
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      VolatilityPoint other = (VolatilityPoint) obj;
      return JodaBeanUtils.equal(getSwapTenor(), other.getSwapTenor()) &&
          JodaBeanUtils.equal(getOptionExpiry(), other.getOptionExpiry()) &&
          JodaBeanUtils.equal(getRelativeStrike(), other.getRelativeStrike());
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = getClass().hashCode();
    hash = hash * 31 + JodaBeanUtils.hashCode(getSwapTenor());
    hash = hash * 31 + JodaBeanUtils.hashCode(getOptionExpiry());
    hash = hash * 31 + JodaBeanUtils.hashCode(getRelativeStrike());
    return hash;
  }

  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder(128);
    buf.append("VolatilityPoint{");
    int len = buf.length();
    toString(buf);
    if (buf.length() > len) {
      buf.setLength(buf.length() - 2);
    }
    buf.append('}');
    return buf.toString();
  }

  protected void toString(StringBuilder buf) {
    buf.append("swapTenor").append('=').append(JodaBeanUtils.toString(getSwapTenor())).append(',').append(' ');
    buf.append("optionExpiry").append('=').append(JodaBeanUtils.toString(getOptionExpiry())).append(',').append(' ');
    buf.append("relativeStrike").append('=').append(JodaBeanUtils.toString(getRelativeStrike())).append(',').append(' ');
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code VolatilityPoint}.
   */
  public static class Meta extends DirectMetaBean {
    /**
     * The singleton instance of the meta-bean.
     */
    static final Meta INSTANCE = new Meta();

    /**
     * The meta-property for the {@code swapTenor} property.
     */
    private final MetaProperty<Tenor> _swapTenor = DirectMetaProperty.ofReadWrite(
        this, "swapTenor", VolatilityPoint.class, Tenor.class);
    /**
     * The meta-property for the {@code optionExpiry} property.
     */
    private final MetaProperty<Tenor> _optionExpiry = DirectMetaProperty.ofReadWrite(
        this, "optionExpiry", VolatilityPoint.class, Tenor.class);
    /**
     * The meta-property for the {@code relativeStrike} property.
     */
    private final MetaProperty<Double> _relativeStrike = DirectMetaProperty.ofReadWrite(
        this, "relativeStrike", VolatilityPoint.class, Double.TYPE);
    /**
     * The meta-properties.
     */
    private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
        this, null,
        "swapTenor",
        "optionExpiry",
        "relativeStrike");

    /**
     * Restricted constructor.
     */
    protected Meta() {
    }

    @Override
    protected MetaProperty<?> metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case -1282130707:  // swapTenor
          return _swapTenor;
        case 1032553992:  // optionExpiry
          return _optionExpiry;
        case 776076702:  // relativeStrike
          return _relativeStrike;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder<? extends VolatilityPoint> builder() {
      return new DirectBeanBuilder<VolatilityPoint>(new VolatilityPoint());
    }

    @Override
    public Class<? extends VolatilityPoint> beanType() {
      return VolatilityPoint.class;
    }

    @Override
    public Map<String, MetaProperty<?>> metaPropertyMap() {
      return _metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-property for the {@code swapTenor} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<Tenor> swapTenor() {
      return _swapTenor;
    }

    /**
     * The meta-property for the {@code optionExpiry} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<Tenor> optionExpiry() {
      return _optionExpiry;
    }

    /**
     * The meta-property for the {@code relativeStrike} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<Double> relativeStrike() {
      return _relativeStrike;
    }

    //-----------------------------------------------------------------------
    @Override
    protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
      switch (propertyName.hashCode()) {
        case -1282130707:  // swapTenor
          return ((VolatilityPoint) bean).getSwapTenor();
        case 1032553992:  // optionExpiry
          return ((VolatilityPoint) bean).getOptionExpiry();
        case 776076702:  // relativeStrike
          return ((VolatilityPoint) bean).getRelativeStrike();
      }
      return super.propertyGet(bean, propertyName, quiet);
    }

    @Override
    protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
      switch (propertyName.hashCode()) {
        case -1282130707:  // swapTenor
          ((VolatilityPoint) bean).setSwapTenor((Tenor) newValue);
          return;
        case 1032553992:  // optionExpiry
          ((VolatilityPoint) bean).setOptionExpiry((Tenor) newValue);
          return;
        case 776076702:  // relativeStrike
          ((VolatilityPoint) bean).setRelativeStrike((Double) newValue);
          return;
      }
      super.propertySet(bean, propertyName, newValue, quiet);
    }

  }

  ///CLOVER:ON
  //-------------------------- AUTOGENERATED END --------------------------
}
