/*
 *  Copyright 2001-present Stephen Colebourne
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.joda.beans.sample;

import java.util.NoSuchElementException;

import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.TypedMetaBean;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.gen.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.MinimalMetaBean;

/**
 * Mock JavaBean, used for testing.
 */
@BeanDefinition(style = "minimal")
public final class FieldNamesImmutableMinimal implements ImmutableBean {

    /** Field named 'obj' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String obj;
    /** Field named 'other' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String other;
    /** Field named 'propertyName' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String propertyName;
    /** Field named 'newValue' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String newValue;
    /** Field named 'bean' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String bean;
    /** Field named 'beanToCopy' to check for name clashes. */
    @PropertyDefinition(get = "field")
    private final String beanToCopy;

    //------------------------- AUTOGENERATED START -------------------------
    /**
     * The meta-bean for {@code FieldNamesImmutableMinimal}.
     */
    private static final TypedMetaBean<FieldNamesImmutableMinimal> META_BEAN =
            MinimalMetaBean.of(
                    FieldNamesImmutableMinimal.class,
                    new String[] {
                            "obj",
                            "other",
                            "propertyName",
                            "newValue",
                            "bean",
                            "beanToCopy"},
                    () -> new FieldNamesImmutableMinimal.Builder(),
                    b -> b.obj,
                    b -> b.other,
                    b -> b.propertyName,
                    b -> b.newValue,
                    b -> b.bean,
                    b -> b.beanToCopy);

    /**
     * The meta-bean for {@code FieldNamesImmutableMinimal}.
     * @return the meta-bean, not null
     */
    public static TypedMetaBean<FieldNamesImmutableMinimal> meta() {
        return META_BEAN;
    }

    static {
        MetaBean.register(META_BEAN);
    }

    /**
     * Returns a builder used to create an instance of the bean.
     * @return the builder, not null
     */
    public static FieldNamesImmutableMinimal.Builder builder() {
        return new FieldNamesImmutableMinimal.Builder();
    }

    private FieldNamesImmutableMinimal(
            String obj,
            String other,
            String propertyName,
            String newValue,
            String bean,
            String beanToCopy) {
        this.obj = obj;
        this.other = other;
        this.propertyName = propertyName;
        this.newValue = newValue;
        this.bean = bean;
        this.beanToCopy = beanToCopy;
    }

    @Override
    public TypedMetaBean<FieldNamesImmutableMinimal> metaBean() {
        return META_BEAN;
    }

    //-----------------------------------------------------------------------
    /**
     * Returns a builder that allows this bean to be mutated.
     * @return the mutable builder, not null
     */
    public Builder toBuilder() {
        return new Builder(this);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj != null && obj.getClass() == this.getClass()) {
            FieldNamesImmutableMinimal other = (FieldNamesImmutableMinimal) obj;
            return JodaBeanUtils.equal(this.obj, other.obj) &&
                    JodaBeanUtils.equal(this.other, other.other) &&
                    JodaBeanUtils.equal(this.propertyName, other.propertyName) &&
                    JodaBeanUtils.equal(this.newValue, other.newValue) &&
                    JodaBeanUtils.equal(this.bean, other.bean) &&
                    JodaBeanUtils.equal(this.beanToCopy, other.beanToCopy);
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = getClass().hashCode();
        hash = hash * 31 + JodaBeanUtils.hashCode(obj);
        hash = hash * 31 + JodaBeanUtils.hashCode(other);
        hash = hash * 31 + JodaBeanUtils.hashCode(propertyName);
        hash = hash * 31 + JodaBeanUtils.hashCode(newValue);
        hash = hash * 31 + JodaBeanUtils.hashCode(bean);
        hash = hash * 31 + JodaBeanUtils.hashCode(beanToCopy);
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder(224);
        buf.append("FieldNamesImmutableMinimal{");
        buf.append("obj").append('=').append(JodaBeanUtils.toString(obj)).append(',').append(' ');
        buf.append("other").append('=').append(JodaBeanUtils.toString(other)).append(',').append(' ');
        buf.append("propertyName").append('=').append(JodaBeanUtils.toString(propertyName)).append(',').append(' ');
        buf.append("newValue").append('=').append(JodaBeanUtils.toString(newValue)).append(',').append(' ');
        buf.append("bean").append('=').append(JodaBeanUtils.toString(bean)).append(',').append(' ');
        buf.append("beanToCopy").append('=').append(JodaBeanUtils.toString(beanToCopy));
        buf.append('}');
        return buf.toString();
    }

    //-----------------------------------------------------------------------
    /**
     * The bean-builder for {@code FieldNamesImmutableMinimal}.
     */
    public static final class Builder extends DirectFieldsBeanBuilder<FieldNamesImmutableMinimal> {

        private String obj;
        private String other;
        private String propertyName;
        private String newValue;
        private String bean;
        private String beanToCopy;

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

        /**
         * Restricted copy constructor.
         * @param beanToCopy  the bean to copy from, not null
         */
        private Builder(FieldNamesImmutableMinimal beanToCopy) {
            this.obj = beanToCopy.obj;
            this.other = beanToCopy.other;
            this.propertyName = beanToCopy.propertyName;
            this.newValue = beanToCopy.newValue;
            this.bean = beanToCopy.bean;
            this.beanToCopy = beanToCopy.beanToCopy;
        }

        //-----------------------------------------------------------------------
        @Override
        public Object get(String propertyName) {
            switch (propertyName.hashCode()) {
                case 109815:  // obj
                    return this.obj;
                case 106069776:  // other
                    return this.other;
                case -864691712:  // propertyName
                    return this.propertyName;
                case 1368456113:  // newValue
                    return this.newValue;
                case 3019696:  // bean
                    return this.bean;
                case -1343227808:  // beanToCopy
                    return this.beanToCopy;
                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
            }
        }

        @Override
        public Builder set(String propertyName, Object newValue) {
            switch (propertyName.hashCode()) {
                case 109815:  // obj
                    this.obj = (String) newValue;
                    break;
                case 106069776:  // other
                    this.other = (String) newValue;
                    break;
                case -864691712:  // propertyName
                    this.propertyName = (String) newValue;
                    break;
                case 1368456113:  // newValue
                    this.newValue = (String) newValue;
                    break;
                case 3019696:  // bean
                    this.bean = (String) newValue;
                    break;
                case -1343227808:  // beanToCopy
                    this.beanToCopy = (String) newValue;
                    break;
                default:
                    throw new NoSuchElementException("Unknown property: " + propertyName);
            }
            return this;
        }

        @Override
        public Builder set(MetaProperty<?> property, Object value) {
            super.set(property, value);
            return this;
        }

        @Override
        public FieldNamesImmutableMinimal build() {
            return new FieldNamesImmutableMinimal(
                    obj,
                    other,
                    propertyName,
                    newValue,
                    bean,
                    beanToCopy);
        }

        //-----------------------------------------------------------------------
        /**
         * Sets field named 'obj' to check for name clashes.
         * @param obj  the new value
         * @return this, for chaining, not null
         */
        public Builder obj(String obj) {
            this.obj = obj;
            return this;
        }

        /**
         * Sets field named 'other' to check for name clashes.
         * @param other  the new value
         * @return this, for chaining, not null
         */
        public Builder other(String other) {
            this.other = other;
            return this;
        }

        /**
         * Sets field named 'propertyName' to check for name clashes.
         * @param propertyName  the new value
         * @return this, for chaining, not null
         */
        public Builder propertyName(String propertyName) {
            this.propertyName = propertyName;
            return this;
        }

        /**
         * Sets field named 'newValue' to check for name clashes.
         * @param newValue  the new value
         * @return this, for chaining, not null
         */
        public Builder newValue(String newValue) {
            this.newValue = newValue;
            return this;
        }

        /**
         * Sets field named 'bean' to check for name clashes.
         * @param bean  the new value
         * @return this, for chaining, not null
         */
        public Builder bean(String bean) {
            this.bean = bean;
            return this;
        }

        /**
         * Sets field named 'beanToCopy' to check for name clashes.
         * @param beanToCopy  the new value
         * @return this, for chaining, not null
         */
        public Builder beanToCopy(String beanToCopy) {
            this.beanToCopy = beanToCopy;
            return this;
        }

        //-----------------------------------------------------------------------
        @Override
        public String toString() {
            StringBuilder buf = new StringBuilder(224);
            buf.append("FieldNamesImmutableMinimal.Builder{");
            buf.append("obj").append('=').append(JodaBeanUtils.toString(obj)).append(',').append(' ');
            buf.append("other").append('=').append(JodaBeanUtils.toString(other)).append(',').append(' ');
            buf.append("propertyName").append('=').append(JodaBeanUtils.toString(propertyName)).append(',').append(' ');
            buf.append("newValue").append('=').append(JodaBeanUtils.toString(newValue)).append(',').append(' ');
            buf.append("bean").append('=').append(JodaBeanUtils.toString(bean)).append(',').append(' ');
            buf.append("beanToCopy").append('=').append(JodaBeanUtils.toString(beanToCopy));
            buf.append('}');
            return buf.toString();
        }

    }

    //-------------------------- AUTOGENERATED END --------------------------
}
