package persistence.link;

import org.junit.jupiter.api.Test;
import persistence.csv.CSVSerializable;
import persistence.tag.TagEntity;

import java.util.Set;

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

class LinkEntityTest {

	@Test
	void toCSVString() {

		var expected =
				"21" + CSVSerializable.seperator + "hans" + CSVSerializable.seperator + "https://tea.filefighter.de" +
						CSVSerializable.seperator + "1" + CSVSerializable.listSeperator + "2" +
						CSVSerializable.listSeperator + "3" + CSVSerializable.seperator + "name" + CSVSerializable.memberSeperator + "hallo";

		TagEntity tagEntity = new TagEntity("name", "hallo");
		Set<Integer> categoryIds = Set.of(1, 2, 3);
		Set<TagEntity> tags = Set.of(tagEntity);
		var actual = new LinkEntity(21, "hans", "https://tea.filefighter.de", categoryIds, tags).toCSVString();

		assertEquals(expected, actual);

	}

	@Test
	void fromCSVString() {

		var input =
				"21" + CSVSerializable.seperator + "hans" + CSVSerializable.seperator + "https://tea.filefighter.de" +
						CSVSerializable.seperator + "1" + CSVSerializable.listSeperator + "2" +
						CSVSerializable.listSeperator + "3" + CSVSerializable.seperator + "name" + CSVSerializable.memberSeperator + "hallo";

		TagEntity tagEntity = new TagEntity("name", "hallo");
		Set<Integer> categoryIds = Set.of(1, 2, 3);
		Set<TagEntity> tags = Set.of(tagEntity);
		var expected = new LinkEntity(21, "hans", "https://tea.filefighter.de", categoryIds, tags);

		assertEquals(expected, new LinkEntity(input.split(CSVSerializable.seperator)));
	}
}
