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

import org.fundacionjala.automation.framework.pages.admin.home.AdminPage;
import org.fundacionjala.automation.framework.pages.admin.login.LoginPage;
import org.fundacionjala.automation.framework.pages.admin.resource.ResourcePage;
import org.fundacionjala.automation.framework.utils.common.BrowserManager;
import org.fundacionjala.automation.framework.utils.common.PropertiesReader;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class CreateResourceSteps {
	AdminPage home;
	ResourcePage resource;

	@Given("^I Login to Room Manager$")
	public void i_Login_to_Room_Manager() throws Throwable {
		BrowserManager.openBrowser();
		LoginPage login = new LoginPage();
		home = login
					.setUserName(PropertiesReader.getUserName())
					.setPassword(PropertiesReader.getPassword())
					.clickOnSigInButton();
	}

	@When("^I Create a new resource$")
	public void i_Create_a_new_resource() throws Throwable {
		resource = home
			.leftMenu
			.clickOnResourcesButton()
			.clickOnAddButton()
			.setResourceName("nada")
			.setDisplayName("nada")
			.setDescription("New Computer")
			.selectIcon("fa-eye")
			.clickOnSaveButton();
	}

	@Then("^I validate that the resource is diplayed in resource page$")
	public void i_validate_that_the_resource_is_diplayed_in_resource_page() throws Throwable {
		Assert.assertTrue(resource
			.verifyResourceExist("nada"));
	}

	@Then("^after that the resource is deleted$")
	public void after_that_the_resource_is_deleted() throws Throwable {
		resource
			.selectResource("nada")
	   		.clickOnRemoveButton()
			.clickOnRemoveButton();
	}

}

@@ -62,16 +62,40 @@
 ource;%0A%0A
+import java.util.List;%0A%0A
 import o
@@ -302,16 +302,22 @@
 esource.
+Remove
 Resource
@@ -318,24 +318,270 @@
 sourcePage;%0A
+import org.fundacionjala.automation.framework.pages.admin.resource.ResourcePage;%0Aimport org.fundacionjala.automation.framework.utils.api.managers.ResourceAPIManager;%0Aimport org.fundacionjala.automation.framework.utils.api.objects.admin.Resource;%0A
 import org.f
@@ -1068,16 +1068,52 @@
 esource;
+%0A%09RemoveResourcePage removeresource;
 %0A%0A%09@Give
@@ -2089,97 +2089,352 @@
 %7B%0A%09%09
-resource%0A%09%09%09.selectResource(%22nada
+String idResource = %22%22;%0A%09%09List%3CResource%3E listResource = ResourceAPIManager.getRequest(%22http://172.20.208.84:4040/resources
 %22)
+;
 %0A%09
-   %09%09.clickOnRemoveButton()%0A%09%09%09.clickOnRemoveButton(
+%09for (Resource resource : listResource) %7B%0A%09%09%09if(resource.name.equalsIgnoreCase(%22nada%22))%0A%09%09%09%7B%0A%09%09%09%09idResource = resource._id;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09ResourceAPIManager.deleteRequest(%22http://172.20.208.84:4040/resources%22, idResource
 );%0A%09

Add post condition with API