package org.mitallast.queue.raft.state;

import com.google.inject.Inject;
import org.mitallast.queue.common.concurrent.Futures;
import org.mitallast.queue.common.settings.Settings;
import org.mitallast.queue.raft.action.append.AppendRequest;
import org.mitallast.queue.raft.action.append.AppendResponse;
import org.mitallast.queue.raft.action.command.CommandRequest;
import org.mitallast.queue.raft.action.command.CommandResponse;
import org.mitallast.queue.raft.action.join.JoinRequest;
import org.mitallast.queue.raft.action.join.JoinResponse;
import org.mitallast.queue.raft.action.keepalive.KeepAliveRequest;
import org.mitallast.queue.raft.action.keepalive.KeepAliveResponse;
import org.mitallast.queue.raft.action.leave.LeaveRequest;
import org.mitallast.queue.raft.action.leave.LeaveResponse;
import org.mitallast.queue.raft.action.query.QueryRequest;
import org.mitallast.queue.raft.action.query.QueryResponse;
import org.mitallast.queue.raft.action.register.RegisterRequest;
import org.mitallast.queue.raft.action.register.RegisterResponse;
import org.mitallast.queue.raft.action.vote.VoteRequest;
import org.mitallast.queue.raft.action.vote.VoteResponse;

import java.util.concurrent.CompletableFuture;

class StartState extends AbstractState {

    @Inject
    public StartState(Settings settings) {
        super(settings);
    }

    @Override
    public RaftStateType type() {
        return RaftStateType.START;
    }

    @Override
    public CompletableFuture<JoinResponse> join(JoinRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<LeaveResponse> leave(LeaveRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<RegisterResponse> register(RegisterRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<KeepAliveResponse> keepAlive(KeepAliveRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<AppendResponse> append(AppendRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<VoteResponse> vote(VoteRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<CommandResponse> command(CommandRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public CompletableFuture<QueryResponse> query(QueryRequest request) {
        return Futures.completeExceptionally(new IllegalStateException("inactive state"));
    }

    @Override
    public void open() {
    }

    @Override
    public void close() {
    }
}

@@ -174,16 +174,77 @@
 ttings;%0A
+import org.mitallast.queue.raft.IllegalMemberStateException;%0A
 import o
@@ -1600,37 +1600,69 @@
 res.complete
-Exceptionally
+(JoinResponse.builder()%0A            .setError
 (new Illegal
@@ -1653,32 +1653,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -1692,32 +1692,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -1846,37 +1846,70 @@
 res.complete
-Exceptionally
+(LeaveResponse.builder()%0A            .setError
 (new Illegal
@@ -1900,32 +1900,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -1939,32 +1939,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -2102,37 +2102,73 @@
 res.complete
-Exceptionally
+(RegisterResponse.builder()%0A            .setError
 (new Illegal
@@ -2159,32 +2159,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -2198,32 +2198,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -2364,37 +2364,74 @@
 res.complete
-Exceptionally
+(KeepAliveResponse.builder()%0A            .setError
 (new Illegal
@@ -2422,32 +2422,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -2461,32 +2461,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -2618,37 +2618,71 @@
 res.complete
-Exceptionally
+(AppendResponse.builder()%0A            .setError
 (new Illegal
@@ -2673,32 +2673,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -2712,32 +2712,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -2863,37 +2863,69 @@
 res.complete
-Exceptionally
+(VoteResponse.builder()%0A            .setError
 (new Illegal
@@ -2916,32 +2916,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -2955,32 +2955,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -3115,37 +3115,72 @@
 res.complete
-Exceptionally
+(CommandResponse.builder()%0A            .setError
 (new Illegal
@@ -3171,32 +3171,38 @@
 rror(new Illegal
+Member
 StateException(%22
@@ -3210,32 +3210,54 @@
 nactive state%22))
+%0A            .build())
 ;%0A    %7D%0A%0A    @Ov
@@ -3372,21 +3372,54 @@
 lete
-Exceptionally
+(QueryResponse.builder()%0A            .setError
 (new
@@ -3426,16 +3426,22 @@
  Illegal
+Member
 StateExc
@@ -3465,16 +3465,38 @@
 state%22))
+%0A            .build())
 ;%0A    %7D%0A

fix start state