package io.quarkus.rest.client.reactive.headers;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;

import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.test.common.http.TestHTTPResource;

public class HeaderTest {
    @RegisterExtension
    static final QuarkusUnitTest config = new QuarkusUnitTest()
            .withApplicationRoot((jar) -> jar.addClasses(Resource.class));

    @TestHTTPResource
    URI baseUri;

    @Test
    void testHeadersWithSubresource() {
        Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);
        assertThat(client.cookieSub("bar", "bar2").send("bar3", "bar4")).isEqualTo("bar:bar2:bar3:bar4");
    }

    @Test
    void testNullHeaders() {
        Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);
        assertThat(client.cookieSub("bar", null).send(null, "bar4")).isEqualTo("bar:null:null:bar4");
    }

    @Path("/")
    @ApplicationScoped
    public static class Resource {
        @GET
        public String returnHeaders(@HeaderParam("foo") String header, @HeaderParam("foo2") String header2,
                @HeaderParam("foo3") String header3, @HeaderParam("foo4") String header4) {
            return header + ":" + header2 + ":" + header3 + ":" + header4;
        }
    }

    public interface Client {

        @Path("/")
        SubClient cookieSub(@HeaderParam("foo") String cookie, @HeaderParam("foo2") String cookie2);
    }

    public interface SubClient {

        @GET
        String send(@HeaderParam("foo3") String cookie3, @HeaderParam("foo4") String cookie4);
    }

}

@@ -255,16 +255,86 @@
 rs.Path;
+%0Aimport javax.ws.rs.core.Context;%0Aimport javax.ws.rs.core.HttpHeaders;
 %0A%0Aimport
@@ -390,16 +390,63 @@
 uilder;%0A
+import org.jboss.resteasy.reactive.RestHeader;%0A
 import o
@@ -1059,34 +1059,60 @@
 d(%22bar3%22, %22bar4%22
-))
+, %22dummy%22))%0A                
 .isEqualTo(%22bar:
@@ -1121,24 +1121,42 @@
 r2:bar3:bar4
+:X-My-Header/dummy
 %22);%0A    %7D%0A%0A 
@@ -1352,16 +1352,25 @@
 , %22bar4%22
+, %22dummy%22
 )).isEqu
@@ -1393,16 +1393,34 @@
 ull:bar4
+:X-My-Header/dummy
 %22);%0A    
@@ -1708,85 +1708,375 @@
 der4
-) %7B%0A            return header + %22:%22 + header2 + %22:%22 + header3 + %22:%22 + header4
+, @Context HttpHeaders headers) %7B%0A            String myHeaderName = headers.getRequestHeaders().keySet().stream().filter(s -%3E s.equalsIgnoreCase(%22X-My-Header%22))%0A                    .findFirst().orElse(%22%22);%0A            return header + %22:%22 + header2 + %22:%22 + header3 + %22:%22 + header4 + %22:%22 + myHeaderName + %22/%22%0A                    + headers.getHeaderString(%22X-My-Header%22)
 ;%0A  
@@ -2287,32 +2287,32 @@
 %7B%0A%0A        @GET%0A
-
         String s
@@ -2387,16 +2387,46 @@
  cookie4
+, @RestHeader String xMyHeader
 );%0A    %7D

Add test for client usage of @RestHeader on the Reactive REST Client