package dev.lions.unionflow.server.common;

import org.junit.jupiter.api.Test;

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

class ErrorResponseTest {

    @Test
    void constructorAndAccessors() {
        ErrorResponse response = new ErrorResponse("some message", "some error");
        assertThat(response.message()).isEqualTo("some message");
        assertThat(response.error()).isEqualTo("some error");
    }

    @Test
    void of_setsMessageNullError() {
        ErrorResponse response = ErrorResponse.of("something went wrong");
        assertThat(response.message()).isEqualTo("something went wrong");
        assertThat(response.error()).isNull();
    }

    @Test
    void ofError_setsErrorNullMessage() {
        ErrorResponse response = ErrorResponse.ofError("NOT_FOUND");
        assertThat(response.error()).isEqualTo("NOT_FOUND");
        assertThat(response.message()).isNull();
    }

    @Test
    void record_equality() {
        ErrorResponse r1 = new ErrorResponse("msg", "err");
        ErrorResponse r2 = new ErrorResponse("msg", "err");
        assertThat(r1).isEqualTo(r2);
        assertThat(r1.hashCode()).isEqualTo(r2.hashCode());
    }

    @Test
    void record_toString_containsFields() {
        ErrorResponse response = new ErrorResponse("hello", "world");
        assertThat(response.toString()).contains("hello").contains("world");
    }
}
