package creditfair_website_config;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.LocalFileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;

import io.github.cdimascio.dotenv.Dotenv;

public class WebsiteBrowswer {
	public static WebDriver driver;
	protected String clientid;
	protected String clientsecret;
	protected String mailgundomain;
	protected String mailgunsecret;


	public static WebDriver getDriver() throws MalformedURLException {
		if (driver == null) {
			
			 //Firefox browser
//			System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
//			FirefoxOptions options = new FirefoxOptions();
//			options.setHeadless(true);
//			driver = new FirefoxDriver();
		    
			//Chrome browser
//			ChromeOptions option = new ChromeOptions();
//			option.addArguments("--remote-allow-origins=*");
//			option.setHeadless(false);			
//		    driver = new ChromeDriver(option);
//		    driver.get("https://test2.creditfair.in/application");
//			driver.manage().window().maximize();
			
			// For Docker Run
			FirefoxOptions options = new FirefoxOptions();
			options.setHeadless(false);
			driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options); 
			((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
			driver.get("https://test2.creditfair.in/application");
		}
		return driver;

	}
	
	public void env ()
	{
		 Dotenv dotenv = null;
	        dotenv = Dotenv.configure().directory("/var/www/html/creditfairadmin").load();
	        clientid= dotenv.get("X-Client-Id");
	        clientsecret=dotenv.get("X-Client-Secret");
	        mailgundomain=dotenv.get("MAILGUN_DOMAIN");
	        mailgunsecret=dotenv.get("MAILGUN_SECRET");
		

	}
	
	
}
