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

import org.fundacionjala.automation.framework.pages.admin.login.LoginPage;
import org.fundacionjala.automation.framework.pages.admin.resource.RemoveResourcePage;
import org.fundacionjala.automation.framework.pages.admin.resource.ResourcePage;
import org.fundacionjala.automation.framework.utils.common.BrowserManager;
import org.testng.Assert;

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

public class DeleteResourceSteps {

	@Given("^I have a resource created with the name \"([^\"]*)\"$")
	public void i_have_a_resource_created_with_the_name(String arg1) throws Throwable {
	    // Write code here that turns the phrase above into concrete actions
		BrowserManager.openBrowser();
		LoginPage login = new LoginPage();
		
		login
			.setUserName("SamuelSahonero")
			.setPassword("Control123!")
			.clickOnSigInButton()
			.leftMenu
			.clickOnResourcesButton()
			.clickOnAddButton()
			.setResourceName(arg1)
			.setDisplayName(arg1)
			.setDescription(arg1)
			.clickOnSaveButton();
	}

	@When("^I delete the resource with the name \"([^\"]*)\"$")
	public void i_delete_the_resource_with_the_name(String arg1) throws Throwable {
	   ResourcePage resource = new ResourcePage();
	   
	   resource
	   		.selectResource(arg1)
	   		.clickOnRemoveButton();
	}

	@When("^Confirm the changes$")
	public void confirm_the_changes() throws Throwable {
	    RemoveResourcePage removeResource = new RemoveResourcePage();
	   
	    removeResource.clickOnRemoveButton();
	}

	@Then("^I verify that the resource with the name \"([^\"]*)\" has been deleted$")
	public void i_verify_that_the_resource_with_the_name_has_been_deleted(String arg1) throws Throwable {
		ResourcePage resource = new ResourcePage();
		
		boolean isResourcePresent = !resource.verifyResourceExist(arg1);
		
		Assert.assertTrue(isResourcePresent);
		
		BrowserManager.getDriver().quit();
	}
}

@@ -297,32 +297,197 @@
 e.ResourcePage;%0A
+import org.fundacionjala.automation.framework.utils.api.managers.ResourceAPIManager;%0Aimport org.fundacionjala.automation.framework.utils.api.objects.admin.Resource;%0A
 import org.funda
@@ -868,628 +868,522 @@
  %7B%0A%09
-    // Write code here that turns the phrase above into concrete actions%0A%09%09BrowserManager.openBrowser();%0A%09%09LoginPage login = new LoginPage();%0A%09%09%0A%09%09login%0A%09%09%09.setUserName(%22SamuelSahonero%22)%0A%09%09%09.setPassword(%22Control123!%22)%0A%09%09%09.clickOnSigInButton()%0A%09%09%09.leftMenu%0A%09%09%09.clickOnResourcesButton()%0A%09%09%09.clickOnAddButton()%0A%09%09%09.setResourceName(arg1)%0A%09%09%09.setDisplayName(arg1)%0A%09%09%09.setDescription(arg1)%0A%09%09%09.clickOnSaveButton();%0A%09%7D%0A%0A%09@When(%22%5EI delete the resource with the name %5C%22(%5B%5E%5C%22%5D*)%5C%22$%22)%0A%09public void i_delete_the_resource_with_the_name(String arg1) throws Throwable %7B%0A%09   ResourcePage resource = new ResourcePage
+%09Resource resource = new Resource(arg1, arg1, %22fa fa-fire%22, %22%22, arg1);%0A%09%09ResourceAPIManager.postRequest(%22http://172.20.208.84:4040/resources%22, resource);%0A%09%7D%0A%0A%09@When(%22%5EI delete the resource with the name %5C%22(%5B%5E%5C%22%5D*)%5C%22$%22)%0A%09public void i_delete_the_resource_with_the_name(String arg1) throws Throwable %7B%0A%09    BrowserManager.openBrowser();%0A%09%09LoginPage login = new LoginPage();%0A%09%09%0A%09%09login%0A%09%09%09.setUserName(%22SamuelSahonero%22)%0A%09%09%09.setPassword(%22Control123!%22)%0A%09%09%09.clickOnSigInButton
 ()
-;
 %0A%09
-   %0A%09   resource
+%09%09.leftMenu%0A%09%09%09.clickOnResourcesButton()
 %0A%09  
@@ -1995,48 +1995,8 @@
 t);%0A
-%09%09%0A%09%09BrowserManager.getDriver().quit();%0A
 %09%7D%0A%7D

Remove Resource Scenario API pre-condition added and implemented