package com.realnet.angulardatatype.Services;
import com.realnet.angulardatatype.Repository.Dv2Repository;
import com.realnet.angulardatatype.Entity.Dv2
;import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import com.realnet.SequenceGenerator.Service.SequenceService;
import com.realnet.Notification.Entity.NotificationService;
import org.springframework.data.domain.Page;
import com.realnet.realm.Entity.Realm;
import com.realnet.realm.Services.RealmService;
import org.springframework.data.domain.Pageable;
import org.springframework.http.*;import com.realnet.users.service1.AppUserServiceImpl;
import com.realnet.users.entity1.AppUser;
















import com.realnet.config.EmailService;


	import org.springframework.stereotype.Service;

@Service
 public class Dv2Service {
@Autowired
private Dv2Repository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;















@Autowired
	private EmailService emailServicestatic;

public Dv2 Savedata(Dv2 data) {

















 

try 
		   {

		// emailServicestatic.sendEmail( getUser().getEmail(),"Dv2", "test");
		emailServicestatic.sendEmailViaSetu(getUser().getEmail(),"test","","ganesh");

} catch (Exception e) {
			// TODO: handle exception
			System.out.println("Got error  During Mail Send " + e);
		}

 


	data.setUpdatedBy(getUser().getUserId());
		data.setCreatedBy(getUser().getUserId());
		data.setAccountId(getUser().getAccount().getAccount_id());
Dv2 save = Repository.save(data);
				return save;	
			}


//	get all with pagination
	public Page<Dv2> getAllWithPagination(Pageable page) {
		return Repository.findAll(page, getUser().getUserId());
	}			
public List<Dv2> getdetails() {  
		List<Realm> realm = realmService.findByUserId(getUser().getUserId());
List<Dv2> all = Repository.findAll(getUser().getUserId());
		
		return all ;		}


public Dv2 getdetailsbyId(Integer id) {
	return Repository.findById(id).get();
			}


	public void delete_by_id(Integer id) {
 Repository.deleteById(id);
}


public Dv2 update(Dv2 data,Integer id) {
	Dv2 old = Repository.findById(id).get();

 
old.setName(data.getName());
 

 
old.setLast_name(data.getLast_name());
 

  


 
old.setTest(data.getTest());
 

  

old.setCurrency(data.getCurrency());

old.setCurrency2(data.getCurrency2());

old.setQrcode_field(data.getQrcode_field());

old.setQrcode_field2(data.getQrcode_field2());

old.setBarcode_field(data.getBarcode_field());

old.setBarcode_field2(data.getBarcode_field2());



final Dv2 test = Repository.save(old);
		data.setUpdatedBy(getUser().getUserId());
  return test;} 


















 public AppUser getUser() {
		AppUser user = userService.getLoggedInUser();
		return user;

	}}
