package com.github.ssindelar.ps2parser;

import org.testng.AssertJUnit;
import org.testng.annotations.Test;

import com.github.ssindelar.ps2parser.data.profile.ApiProfile;
import com.github.ssindelar.ps2parser.data.profile.ProfileResponse;
import com.github.ssindelar.ps2parser.data.profile.type.ApiProfileType;
import com.github.ssindelar.ps2parser.data.profile.type.ProfileTypeResponse;

public class ProfileDaoTest {

	private static final long PROFILE_ID = 9;
	private static final String PROFILE_NAME_EN = "Facility Object NPC";
	private static final String PROFILE_NAME_DE = "Objekt der Einrichtung (NPC)";

	private static final long PROFILE_TYPE_ID = 7;
	private static final String PROFILE_TYPE_NAME = "MAX";
	private static final String PROFILE_TYPE_CODE = "max";

	private final ProfileApiDAO profileDao = TestData.API_CONNECTION.getProfileDao();

	@Test
	public void getProfileById() {
		ProfileResponse profileRequest = this.profileDao.getProfile(ProfileDaoTest.PROFILE_ID);
		AssertJUnit.assertNotNull("Profilerequest didn't return anything", profileRequest);
		ApiProfile profile = profileRequest.getProfiles().get(0);
		AssertJUnit.assertNotNull("Profile not found", profile);
		AssertJUnit.assertEquals("Profile english name wrong", ProfileDaoTest.PROFILE_NAME_EN,
				profile.getName().get("en"));
		AssertJUnit.assertEquals("Profile german name wrong", ProfileDaoTest.PROFILE_NAME_DE,
				profile.getName().get("de"));
		AssertJUnit.assertEquals("Profile id wrong", String.valueOf(ProfileDaoTest.PROFILE_ID), profile.getId());
	}

	@Test
	public void getProfileTypeById() {
		ProfileTypeResponse profileRequest = this.profileDao.getProfileType(ProfileDaoTest.PROFILE_TYPE_ID);
		AssertJUnit.assertNotNull("Profiletype request didn't return anything", profileRequest);
		ApiProfileType profileType = profileRequest.getProfileTypes().get(0);
		this.validateProfileType(profileType);
	}

	@Test
	public void getProfileTypeByName() {
		ProfileTypeResponse profileRequest = this.profileDao.getProfileType(ProfileDaoTest.PROFILE_TYPE_NAME);
		AssertJUnit.assertNotNull("Profiletype request didn't return anything", profileRequest);
		ApiProfileType profileType = profileRequest.getProfileTypes().get(0);
		this.validateProfileType(profileType);
	}

	@Test
	public void getProfileTypeByCode() {
		ProfileTypeResponse profileRequest = this.profileDao.getProfileTypeByCode(ProfileDaoTest.PROFILE_TYPE_CODE);
		AssertJUnit.assertNotNull("Profiletype request didn't return anything", profileRequest);
		ApiProfileType profileType = profileRequest.getProfileTypes().get(0);
		this.validateProfileType(profileType);
	}

	private void validateProfileType(ApiProfileType type) {
		AssertJUnit.assertNotNull("Profiletype not found", type);
		AssertJUnit.assertEquals("Profiletype name wrong", ProfileDaoTest.PROFILE_TYPE_NAME, type.getName());
		AssertJUnit.assertEquals("Profiletype code wrong", ProfileDaoTest.PROFILE_TYPE_CODE, type.getCode());
		AssertJUnit.assertEquals("Profiletype id wrong", String.valueOf(ProfileDaoTest.PROFILE_TYPE_ID), type.getId());
	}

}
