package com.realnet.app-b.Services;
import com.realnet.app-b.Repository.PasswordgeneratorRepository;
import com.realnet.app-b.Entity.Passwordgenerator
;import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import com.realnet.SequenceGenerator.Service.SequenceService;
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 org.springframework.stereotype.Service;

@Service
 public class PasswordgeneratorService {
@Autowired
private PasswordgeneratorRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;











public Passwordgenerator Savedata(Passwordgenerator data) {












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


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


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


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


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

old.setInclude_uppercase(data.getInclude_uppercase());

old.setInclude_lowercase(data.getInclude_lowercase());

old.setInclude_numbers(data.getInclude_numbers());

old.setInclude_symbols(data.getInclude_symbols());

old.setGenerated_password(data.getGenerated_password());

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












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

	}}
