package com.oguerreiro.resilient.domain;

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

public class MetadataPropertyAsserts {

    /**
     * Asserts that the entity has all properties (fields/relationships) set.
     *
     * @param expected the expected entity
     * @param actual the actual entity
     */
    public static void assertMetadataPropertyAllPropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
        assertMetadataPropertyAutoGeneratedPropertiesEquals(expected, actual);
        assertMetadataPropertyAllUpdatablePropertiesEquals(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 assertMetadataPropertyAllUpdatablePropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
        assertMetadataPropertyUpdatableFieldsEquals(expected, actual);
        assertMetadataPropertyUpdatableRelationshipsEquals(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 assertMetadataPropertyAutoGeneratedPropertiesEquals(MetadataProperty expected, MetadataProperty actual) {
        assertThat(expected)
            .as("Verify MetadataProperty 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 assertMetadataPropertyUpdatableFieldsEquals(MetadataProperty expected, MetadataProperty actual) {
        assertThat(expected)
            .as("Verify MetadataProperty relevant properties")
            .satisfies(e -> assertThat(e.getCode()).as("check code").isEqualTo(actual.getCode()))
            .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.getMandatory()).as("check mandatory").isEqualTo(actual.getMandatory()))
            .satisfies(e -> assertThat(e.getMetadataType()).as("check metadataType").isEqualTo(actual.getMetadataType()))
            .satisfies(e -> assertThat(e.getPattern()).as("check pattern").isEqualTo(actual.getPattern()))
            .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 assertMetadataPropertyUpdatableRelationshipsEquals(MetadataProperty expected, MetadataProperty actual) {
        assertThat(expected)
            .as("Verify MetadataProperty relationships")
            .satisfies(e -> assertThat(e.getOrganizationTypes()).as("check organizationTypes").isEqualTo(actual.getOrganizationTypes()));
    }
}
