/*
 * Copyright 2018, TeamDev. All rights reserved.
 *
 * Redistribution and use in source and/or binary forms, with or without
 * modification, must retain the above copyright notice and the following
 * disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package io.spine.server.model;

import java.lang.reflect.Method;

import static java.lang.String.format;

/**
 * An error indicating that two message handlers have clashing {@link io.spine.core.ByField ByField}
 * signatures.
 *
 * @author Dmytro Dashenkov
 */
public class HandlerFieldFilterClashError extends ModelError {

    private static final long serialVersionUID = 0L;

    HandlerFieldFilterClashError(Class<?> containingClass,
                                 Method firstMethod,
                                 Method secondMethod) {
        super(format("Handler class %s declares methods %s and %s with clashing field filters.%n" +
                             "It's only allowed to filter by one field per message type.",
                     containingClass.getName(), firstMethod, secondMethod));
    }
}

@@ -1235,16 +1235,734 @@
 res.%0A *%0A
+ * %3Cp%3ETwo handlers clash if they handle the same type of message but filter messages by different%0A * fields. For example:%0A * %3Cpre%3E%0A *     %7B@code%0A *     %5C@Subscribe(filter = @ByField(path = %22member_count%22, value = %220%22))%0A *     public void onProject(ProjectStarted event) %7B%0A *     %7D%0A *%0A       %5C@Subscribe(filter = @ByField(path = %22by.admin%22, value = %22false%22))%0A *     public void onStarted(ProjectStarted event) %7B%0A *     %7D%0A *     %7D%0A * %3C/pre%3E%0A *%0A * %3Cp%3EBoth methods %7B@code onProject%7D and %7B@code onStarted%7D subscribe to %7B@code ProjectStarted%7D but%0A * filter the events by %7B@code member_count%7D and %7B@code by.admin%7D fields respectively. This is%0A * an invalid situation, since both filters could be satisfied simultaneously.%0A *%0A
  * @auth

Document handler clash situation.