package dev.lions.unionflow.server.exception;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.security.TestSecurity;
import io.restassured.http.ContentType;
import java.util.UUID;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@QuarkusTest
class BusinessExceptionMapperTest {

    @Test
    @TestSecurity(user = "admin@unionflow.com", roles = { "ADMIN" })
    @DisplayName("IllegalArgumentException → 400 + body error/message")
    void toResponse_IllegalArgumentException_returns400() {
        given()
                .contentType(ContentType.JSON)
                .body("{}")
                .when()
                .post("/api/membres/search/advanced")
                .then()
                .statusCode(400)
                .body("error", notNullValue())
                .body("status", equalTo(400));
    }

    @Test
    @TestSecurity(user = "admin@unionflow.com", roles = { "ADMIN" })
    @DisplayName("NotFoundException → 404 + body error/message")
    void toResponse_NotFoundException_returns404() {
        given()
                .pathParam("id", UUID.randomUUID())
                .when()
                .get("/api/membres/{id}")
                .then()
                .statusCode(404)
                .body("error", notNullValue())
                .body("status", equalTo(404));
    }

    @Test
    @TestSecurity(user = "admin@unionflow.com", roles = { "ADMIN" })
    @DisplayName("NotFoundException événement → 404")
    void toResponse_NotFoundException_event_returns404() {
        given()
                .pathParam("id", UUID.randomUUID())
                .when()
                .get("/api/evenements/{id}")
                .then()
                .statusCode(404)
                .body("error", notNullValue())
                .body("status", equalTo(404));
    }

    @Test
    @TestSecurity(user = "admin@unionflow.com", roles = { "ADMIN" })
    @DisplayName("NotFoundException organisation → 404")
    void toResponse_NotFoundException_organisation_returns404() {
        given()
                .pathParam("id", UUID.randomUUID())
                .when()
                .get("/api/organisations/{id}")
                .then()
                .statusCode(404)
                .body("error", notNullValue())
                .body("status", equalTo(404));
    }
}
