package com.oguerreiro.resilient.domain;

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

public class UnitAsserts {

    /**
     * Asserts that the entity has all properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assertUnitAllPropertiesEquals(Unit expected, Unit actual) {
        assertUnitAutoGeneratedPropertiesEquals(expected, actual);
        assertUnitAllUpdatablePropertiesEquals(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 assertUnitAllUpdatablePropertiesEquals(Unit expected, Unit actual) {
        assertUnitUpdatableFieldsEquals(expected, actual);
        assertUnitUpdatableRelationshipsEquals(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 assertUnitAutoGeneratedPropertiesEquals(Unit expected, Unit actual) {
        assertThat(expected)
            .as("Verify Unit 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 assertUnitUpdatableFieldsEquals(Unit expected, Unit actual) {
        assertThat(expected)
            .as("Verify Unit relevant properties")
            .satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
            .satisfies(e -> assertThat(e.getSymbol()).as("check symbol").isEqualTo(actual.getSymbol()))
            .satisfies(e -> assertThat(e.getName()).as("check name").isEqualTo(actual.getName()))
            .satisfies(e -> assertThat(e.getDescription()).as("check description").isEqualTo(actual.getDescription()))
            .satisfies(
                e ->
                    assertThat(e.getConvertionRate())
                        .as("check convertionRate")
                        .usingComparator(bigDecimalCompareTo)
                        .isEqualTo(actual.getConvertionRate())
            )
            .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 assertUnitUpdatableRelationshipsEquals(Unit expected, Unit actual) {
        assertThat(expected)
            .as("Verify Unit relationships")
            .satisfies(e -> assertThat(e.getUnitType()).as("check unitType").isEqualTo(actual.getUnitType()));
    }
}
