package org.fundacionjala.automation.scenario.steps.admin.location;

import org.fundacionjala.automation.framework.pages.admin.login.LoginPage;
import org.fundacionjala.automation.framework.utils.api.managers.LocationAPIManager;
import org.fundacionjala.automation.framework.utils.api.objects.admin.Location;
import org.fundacionjala.automation.framework.utils.common.BrowserManager;
import org.fundacionjala.automation.framework.utils.common.PropertiesReader;

import cucumber.api.java.en.Given;

public class LocationGivenSteps {
	
	@Given("^I am logged as \"([^\"]*)\" with password \"([^\"]*)\"$")
	public void logInWithAnAccount(String userName, 
				       String password) throws Throwable {
		
		BrowserManager.openBrowser();
		LoginPage loginPage = new LoginPage();
		
		loginPage
			.setUserName(userName)
			.setPassword(password)
			.clickOnSigInButton();
	}
	
	@Given("^I have a location added with name: \"([^\"]*)\", display name \"([^\"]*)\" and description \"([^\"]*)\"$")
	public void addLocation(String name, 
				String displayName, 
				String description) throws Throwable {
		try {
			LocationAPIManager.postRequest(PropertiesReader.getServiceURL() 
					+ "/locations", 
					new Location(name, displayName, "", "", description));

			
		} catch (Exception e) {
		}
		}
}

@@ -137,16 +137,101 @@
 inPage;%0A
+import org.fundacionjala.automation.framework.pages.admin.resource.ResourcesActions;%0A
 import o
@@ -387,16 +387,96 @@
 cation;%0A
+import org.fundacionjala.automation.framework.utils.api.objects.admin.Resource;%0A
 import o
@@ -1452,10 +1452,517 @@
 %09%09%7D%0A%09%09%7D%0A
+%09%0A%09@Given(%22%5EI have at least %5C%22(%5B%5E%5C%22%5D*)%5C%22 locations created$%22)%0A%09public void i_have_at_least_locations_created(String locationQuantity) throws Throwable %7B%0A%09%09int quantity = Integer.parseInt(locationQuantity);%0A%09%09for (int i = 0; i %3C quantity; i++) %7B%0A%09%09%09Location location = new Location(%22location%22 + i,%0A%09%09%09%09%09%09%09%09%09%09%09 %22displayName%22 + i,%0A%09%09%09%09%09%09%09%09%09%09%09 %22%22, %22%22, %0A%09%09%09%09%09%09%09%09%09%09%09 %22This is a new Location %22+i+%22 added%22);%0A%09%09%09LocationAPIManager.postRequest(PropertiesReader.getServiceURL() %0A%09%09%09%09%09+ %22/locations%22, location);%0A%09%09%7D%0A%09%7D%0A
 %7D%0A

Fix Framework: LocationGivenSteps