package dev.lions.unionflow.client.view;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import dev.lions.unionflow.client.api.dto.PispiReadinessDto;
import java.lang.reflect.Field;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

class PispiReadinessBeanTest {

  private PispiReadinessBean bean;

  @BeforeEach
  void setUp() {
    bean = new PispiReadinessBean();
  }

  private void setReadiness(PispiReadinessDto r) throws Exception {
    Field f = PispiReadinessBean.class.getDeclaredField("readiness");
    f.setAccessible(true);
    f.set(bean, r);
  }

  @Test
  @DisplayName("couleurStatus — null → secondary")
  void couleurNull() {
    assertEquals("secondary", bean.getCouleurStatus());
  }

  @Test
  @DisplayName("couleurStatus — READY → success")
  void couleurReady() throws Exception {
    setReadiness(new PispiReadinessDto("READY", "url", List.of(), List.of(), List.of()));
    assertEquals("success", bean.getCouleurStatus());
  }

  @Test
  @DisplayName("couleurStatus — DEGRADED → warning")
  void couleurDegraded() throws Exception {
    setReadiness(new PispiReadinessDto("DEGRADED", "url", List.of(), List.of(), List.of()));
    assertEquals("warning", bean.getCouleurStatus());
  }

  @Test
  @DisplayName("couleurStatus — BLOCKED → danger")
  void couleurBlocked() throws Exception {
    setReadiness(new PispiReadinessDto("BLOCKED", "url", List.of(), List.of(), List.of()));
    assertEquals("danger", bean.getCouleurStatus());
  }

  @Test
  @DisplayName("couleurCheck — PASS → success quel que soit severity")
  void couleurCheckPass() {
    assertEquals("success", bean.getCouleurCheck("BLOCKING", "PASS"));
    assertEquals("success", bean.getCouleurCheck("WARNING", "PASS"));
  }

  @Test
  @DisplayName("couleurCheck — FAIL BLOCKING → danger")
  void couleurCheckFailBlocking() {
    assertEquals("danger", bean.getCouleurCheck("BLOCKING", "FAIL"));
  }

  @Test
  @DisplayName("couleurCheck — FAIL WARNING → warning")
  void couleurCheckFailWarning() {
    assertEquals("warning", bean.getCouleurCheck("WARNING", "FAIL"));
  }

  @Test
  @DisplayName("DTO estReady / estBlocked")
  void dtoStateHelpers() {
    var ready = new PispiReadinessDto("READY", "u", List.of(), List.of(), List.of());
    var blocked = new PispiReadinessDto("BLOCKED", "u", List.of(), List.of(), List.of());
    assertTrue(ready.estReady());
    assertFalse(ready.estBlocked());
    assertFalse(blocked.estReady());
    assertTrue(blocked.estBlocked());
  }
}
