package com.prime.sony.ecommerce.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.apache.commons.lang.time.DurationFormatUtils;

public class AmazonSESSample {

    // Replace sender@example.com with your "From" address.
    // This address must be verified.
    static final String FROM = "no-reply@crm-ecommerce.delphiplatform.io";
    static final String FROMNAME = "Naresh Ginjupalli";
	
    // Replace recipient@example.com with a "To" address. If your account 
    // is still in the sandbox, this address must be verified.
    static final String TO = "nginjupalli@primetgi.com";
    
    // Replace smtp_username with your Amazon SES SMTP user name.
    static final String SMTP_USERNAME = "";
    
    // Replace smtp_password with your Amazon SES SMTP password.
    static final String SMTP_PASSWORD = "";
    
    // The name of the Configuration Set to use for this message.
    // If you comment out or remove this variable, you will also need to
    // comment out or remove the header below.
    static final String CONFIGSET = "ConfigSet";
    
    // Amazon SES SMTP host name. This example uses the US West (Oregon) region.
    // See https://docs.aws.amazon.com/ses/latest/DeveloperGuide/regions.html#region-endpoints
    // for more information.
    static final String HOST = "email-smtp.us-east-1.amazonaws.com";
    
    // The port you will connect to on the Amazon SES SMTP endpoint. 
    static final int PORT = 587;
    
    static final String SUBJECT = "Amazon SES test (SMTP interface accessed using Java)";
    
    static final String BODY = String.join(
    	    System.getProperty("line.separator"),
    	    "<h1>Amazon SES SMTP Email Test</h1>",
    	    "<p>This email was sent with Amazon SES using the ", 
    	    "<a href='https://github.com/javaee/javamail'>Javamail Package</a>",
    	    " for <a href='https://www.java.com'>Java</a>."
    	);

    public static void main(String[] args) throws Exception {

//        // Create a Properties object to contain connection configuration information.
//    	Properties props = System.getProperties();
//    	props.put("mail.transport.protocol", "smtp");
//    	props.put("mail.smtp.host", HOST);
//    	props.put("mail.smtp.port", PORT); 
//    	props.put("mail.smtp.starttls.enable", "true");
//    	props.put("mail.smtp.auth", "true");
//
//        // Create a Session object to represent a mail session with the specified properties. 
//    	//Session session = Session.getDefaultInstance(props);
//    	
//    	Session session = Session.getInstance(props, new Authenticator() {
//			@Override
//			protected PasswordAuthentication getPasswordAuthentication() {
//				return new PasswordAuthentication(SMTP_USERNAME	, SMTP_PASSWORD);
//			}
//		});
//
//        // Create a message with the specified information. 
//        MimeMessage msg = new MimeMessage(session);
//        msg.setFrom(new InternetAddress(FROM,FROMNAME));
//        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(TO));
//        msg.setSubject(SUBJECT);
//        msg.setContent(BODY,"text/html");
//        
//        // Add a configuration set header. Comment or delete the 
//        // next line if you are not using a configuration set
//       // msg.setHeader("X-SES-CONFIGURATION-SET", CONFIGSET);
//            
//        // Create a transport.
//       // Transport transport = session.getTransport();
//                    
//        // Send the message.
//        try
//        {
//            System.out.println("Sending...");
//            
//            // Connect to Amazon SES using the SMTP username and password you specified above.
//           // transport.connect(HOST, SMTP_USERNAME, SMTP_PASSWORD);
//        	
//            // Send the email.
//            Transport.send(msg, msg.getAllRecipients());
//            System.out.println("Email sent!");
//        }
//        catch (Exception ex) {
//            System.out.println("The email was not sent.");
//            System.out.println("Error message: " + ex.getMessage());
//        }
//        finally
//        {
//            // Close and terminate the connection.
//           // transport.close();
//        }
    	TimeZone.setDefault(TimeZone.getTimeZone("EST"));
    	Date startDate = new Date();
    	startDate.setHours(10);
    	startDate.setMinutes(10);
    	startDate.setSeconds(10);
    	Date endDate = new Date();
    	System.out.println(startDate);
    	SimpleDateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:MM:ss");
    	String date = format.format(endDate);
    	System.out.println(date);
    	
    	long millis  = endDate.getTime() - startDate.getTime();
    	
    	System.out.println(millis);

//    	long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
//    	long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration);
//    	long diffInHours = TimeUnit.MILLISECONDS.toHours(duration);
    	//long diffInDays = TimeUnit.MILLISECONDS.toDays(duration);
    	
//    	 String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
//    	            TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
//    	            TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
    	 String hms = DurationFormatUtils.formatDuration(millis, "HH:mm:ss,SSS");
    	System.out.println(hms);
    }
}
