package com.oguerreiro.resilient.domain;

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

public class OutputDataAsserts {

    /**
     * Asserts that the entity has all properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assertOutputDataAllPropertiesEquals(OutputData expected, OutputData actual) {
        assertOutputDataAutoGeneratedPropertiesEquals(expected, actual);
        assertOutputDataAllUpdatablePropertiesEquals(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 assertOutputDataAllUpdatablePropertiesEquals(OutputData expected, OutputData actual) {
        assertOutputDataUpdatableFieldsEquals(expected, actual);
        assertOutputDataUpdatableRelationshipsEquals(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 assertOutputDataAutoGeneratedPropertiesEquals(OutputData expected, OutputData actual) {
        assertThat(expected)
            .as("Verify OutputData 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 assertOutputDataUpdatableFieldsEquals(OutputData expected, OutputData actual) {
        assertThat(expected)
            .as("Verify OutputData relevant properties")
            .satisfies(e -> assertThat(e.getValue()).as("check value").usingComparator(bigDecimalCompareTo).isEqualTo(actual.getValue()))
            .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 assertOutputDataUpdatableRelationshipsEquals(OutputData expected, OutputData actual) {
        assertThat(expected)
            .as("Verify OutputData 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.getPeriodVersion()).as("check periodVersion").isEqualTo(actual.getPeriodVersion()))
            .satisfies(e -> assertThat(e.getBaseUnit()).as("check baseUnit").isEqualTo(actual.getBaseUnit()));
    }
}
