/*
 *  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.beans.ConstructorProperties;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;

import org.joda.beans.ImmutableBean;
import org.joda.beans.MetaBean;
import org.joda.beans.MetaProperty;
import org.joda.beans.gen.BeanDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;

/**
 * Mock immutable empty bean, used for testing.
 * 
 * @author Stephen Colebourne
 */
@BeanDefinition(constructorScope = "public@ConstructorProperties")
public final class ImmEmpty implements ImmutableBean
{
    // NOTE: open braces on a new line

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

    static {
        MetaBean.register(ImmEmpty.Meta.INSTANCE);
    }

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

    /**
     * Creates an instance.
     */
    @ConstructorProperties({})
    public ImmEmpty() {
    }

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

    //-----------------------------------------------------------------------
    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj != null && obj.getClass() == this.getClass()) {
            return true;
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = getClass().hashCode();
        return hash;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder(32);
        buf.append("ImmEmpty{");
        buf.append('}');
        return buf.toString();
    }

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

        /**
         * The meta-properties.
         */
        private final Map<String, MetaProperty<?>> metaPropertyMap$ = new DirectMetaPropertyMap(
                this, null);

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

        @Override
        public ImmEmpty.Builder builder() {
            return new ImmEmpty.Builder();
        }

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

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

        //-----------------------------------------------------------------------
    }

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

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

        //-----------------------------------------------------------------------
        @Override
        public Object get(String propertyName) {
            throw new NoSuchElementException("Unknown property: " + propertyName);
        }

        @Override
        public Builder set(String propertyName, Object newValue) {
            throw new NoSuchElementException("Unknown property: " + propertyName);
        }

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

        @Override
        public ImmEmpty build() {
            return new ImmEmpty();
        }

        //-----------------------------------------------------------------------
        @Override
        public String toString() {
            return "ImmEmpty.Builder{}";
        }

    }

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

    // an inner class with equals/hashCode/toString
    static class InnerClass {
        private final String value;

        public InnerClass(String value) {
            this.value = value;
        }

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

        @Override
        public boolean equals(Object obj) {
            return obj instanceof InnerClass other && Objects.equals(value, other.value);
        }

        @Override
        public String toString() {
            return value;
        }
    }
}
