package com.oguerreiro.resilient.domain;

import static com.oguerreiro.resilient.domain.AssertUtils.bigDecimalCompareTo;
import static org.assertj.core.api.Assertions.assertThat;

public class InputDataAsserts {

  /**
   * Asserts that the entity has all properties (fields/relationships) set.
   *
   * @param expected the expected entity
   * @param actual   the actual entity
   */
  public static void assertInputDataAllPropertiesEquals(InputData expected, InputData actual) {
    assertInputDataAutoGeneratedPropertiesEquals(expected, actual);
    assertInputDataAllUpdatablePropertiesEquals(expected, actual);
  }

  /**
   * Asserts that the entity has all updatable properties (fields/relationships)
   * set.
   *
   * @param expected the expected entity
   * @param actual   the actual entity
   */
  public static void assertInputDataAllUpdatablePropertiesEquals(InputData expected, InputData actual) {
    assertInputDataUpdatableFieldsEquals(expected, actual);
    assertInputDataUpdatableRelationshipsEquals(expected, actual);
  }

  /**
   * Asserts that the entity has all the auto generated properties
   * (fields/relationships) set.
   *
   * @param expected the expected entity
   * @param actual   the actual entity
   */
  public static void assertInputDataAutoGeneratedPropertiesEquals(InputData expected, InputData actual) {
    assertThat(expected).as("Verify InputData auto generated properties")
        .satisfies(e -> assertThat(e.getId()).as("check id").isEqualTo(actual.getId()));
  }

  /**
   * Asserts that the entity has all the updatable fields set.
   *
   * @param expected the expected entity
   * @param actual   the actual entity
   */
  public static void assertInputDataUpdatableFieldsEquals(InputData expected, InputData actual) {
    assertThat(expected).as("Verify InputData relevant properties")
        .satisfies(e -> assertThat(e.getSourceValue()).as("check sourceValue").usingComparator(bigDecimalCompareTo)
            .isEqualTo(actual.getSourceValue()))
        .satisfies(e -> assertThat(e.getVariableValue()).as("check variableValue").usingComparator(bigDecimalCompareTo)
            .isEqualTo(actual.getVariableValue()))
        .satisfies(e -> assertThat(e.getImputedValue()).as("check imputedValue").usingComparator(bigDecimalCompareTo)
            .isEqualTo(actual.getImputedValue()))
        .satisfies(e -> assertThat(e.getSourceType()).as("check sourceType").isEqualTo(actual.getSourceType()))
        .satisfies(e -> assertThat(e.getDataDate()).as("check dataDate").isEqualTo(actual.getDataDate()))
        .satisfies(e -> assertThat(e.getChangeDate()).as("check changeDate").isEqualTo(actual.getChangeDate()))
        .satisfies(
            e -> assertThat(e.getChangeUsername()).as("check changeUsername").isEqualTo(actual.getChangeUsername()))
        .satisfies(e -> assertThat(e.getDataSource()).as("check dataSource").isEqualTo(actual.getDataSource()))
        .satisfies(e -> assertThat(e.getDataUser()).as("check dataUser").isEqualTo(actual.getDataUser()))
        .satisfies(e -> assertThat(e.getDataComments()).as("check dataComments").isEqualTo(actual.getDataComments()))
        .satisfies(e -> assertThat(e.getCreationDate()).as("check creationDate").isEqualTo(actual.getCreationDate()))
        .satisfies(e -> assertThat(e.getCreationUsername()).as("check creationUsername")
            .isEqualTo(actual.getCreationUsername()))
        .satisfies(e -> assertThat(e.getVersion()).as("check version").isEqualTo(actual.getVersion()));
  }

  /**
   * Asserts that the entity has all the updatable relationships set.
   *
   * @param expected the expected entity
   * @param actual   the actual entity
   */
  public static void assertInputDataUpdatableRelationshipsEquals(InputData expected, InputData actual) {
    assertThat(expected).as("Verify InputData relationships")
        .satisfies(e -> assertThat(e.getVariable()).as("check variable").isEqualTo(actual.getVariable()))
        .satisfies(e -> assertThat(e.getPeriod()).as("check period").isEqualTo(actual.getPeriod()))
        .satisfies(e -> assertThat(e.getSourceUnit()).as("check sourceUnit").isEqualTo(actual.getSourceUnit()))
        .satisfies(e -> assertThat(e.getUnit()).as("check unit").isEqualTo(actual.getUnit()))
        .satisfies(e -> assertThat(e.getOwner()).as("check owner").isEqualTo(actual.getOwner()))
        .satisfies(
            e -> assertThat(e.getSourceInputData()).as("check sourceInputData").isEqualTo(actual.getSourceInputData()))
        .satisfies(e -> assertThat(e.getSourceInputDataUpload()).as("check sourceInputDataUpload")
            .isEqualTo(actual.getSourceInputDataUpload()));
  }
}
