package br.com.senai.stayFilm.controller;

import java.net.URI;
import java.net.URISyntaxException;
import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import br.com.senai.stayFilm.bo.ColaboradorLoginBo;
import br.com.senai.stayFilm.model.ColaboradorLogin;
import br.com.senai.stayFilm.sendMail.SendMail;

@RestController
public class ColaboradorLoginRestController {

	@Autowired
	public ColaboradorLoginBo colaboradorLoginBO;

	@RequestMapping(value = "colaborador/colaboradorLogin/{idColaborador}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<ColaboradorLogin> inserir(@PathVariable Long idColaborador,
			@RequestBody ColaboradorLogin colaboradorLogin) throws SQLException {
		try {
			colaboradorLoginBO.insert(colaboradorLogin, idColaborador);
			URI location = new URI("/colaborador" + colaboradorLogin.getIdLoginColaborador());
			return ResponseEntity.created(location).body(colaboradorLogin);
		} catch (URISyntaxException e) {
			e.printStackTrace();
			return new ResponseEntity<>(org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR);
		}

	}
	
	
	@Transactional
	@RequestMapping(value = "/colaboradorLogin/editar/{idColaboradorLogin}/{idColaborador}", method = RequestMethod.PUT)
	public ColaboradorLogin altera(@RequestBody ColaboradorLogin colaboradorLogin, @PathVariable Long idColaborador) throws SQLException {
	
		SendMail sm = new SendMail("smtp.gmail.com","465");

		String origem = colaboradorLogin.getEmail();
		String destino = "emailDestino";
		String assunto = "Assunto";
		String mensagem = "Teste";
		
		sm.sendMail(origem,destino,assunto,mensagem);


		
		return colaboradorLogin;
	}


}

@@ -805,16 +805,173 @@
 endMail;
+%0Aimport br.com.senai.stayFilm.viewModel.ColaboradorLoginViewModel;%0Aimport br.com.senai.stayFilm.vizualizacao.viewModel.ColaboradorLoginVizualizacaoViewModel;
 %0A%0A@RestC
@@ -1328,16 +1328,37 @@
 dorLogin
+VizualizacaoViewModel
 %3E inseri
@@ -1425,33 +1425,35 @@
 dorLogin
- colaboradorLogin
+ViewModel viewModel
 ) throws
@@ -1476,16 +1476,91 @@
 %09%09try %7B%0A
+%09%09%09ColaboradorLogin colaborador = viewModel.toColaboradorLoginViewModel();%0A
 %09%09%09colab
@@ -1591,21 +1591,16 @@
 aborador
-Login
 , idCola
@@ -1659,29 +1659,24 @@
  colaborador
-Login
 .getIdLoginC
@@ -1738,17 +1738,21 @@
 n).body(
-c
+new C
 olaborad
@@ -1758,16 +1758,50 @@
 dorLogin
+VizualizacaoViewModel(colaborador)
 );%0A%09%09%7D c

Insert de colaborador com sucesso