package com.realnet.basicp1.Services;
import com.realnet.basicp1.Repository.Adv3Repository;
import com.realnet.basicp1.Entity.Adv3
;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 com.realnet.Testlist_ListFilter1/Testlist_ListFilter1.Entity.Testlist;

import com.realnet.Testlist_ListFilter1/Testlist_ListFilter1.Repository.TestlistRepository;






	import org.springframework.stereotype.Service;

@Service
 public class Adv3Service {
@Autowired
private Adv3Repository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;







public Adv3 Savedata(Adv3 data) {








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


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


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


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


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





old.setChild(data.getChild());

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



//	Insert Action

	@Autowired
	private TestlistRepository testlistinsertrepository;

public Testlist insertTestlist(Testlist data) {

data.setUpdatedBy(getUser().getUserId());
		data.setCreatedBy(getUser().getUserId());
		data.setAccountId(getUser().getAccount().getAccount_id());


		final Testlist save = testlistinsertrepository.save(data);
		return save;
	}





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

	}}
