package com.realnet.angulardatatype.Services;
import com.realnet.angulardatatype.Repository.Basicp3Repository;
import com.realnet.angulardatatype.Entity.Basicp3
;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 Basicp3Service {
@Autowired
private Basicp3Repository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;















@Autowired
 private SequenceService documentsequencsequenceService;





public Basicp3 Savedata(Basicp3 data) {
















data.setDocumentsequenc (documentsequencsequenceService.GenerateSequence("ff"));





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


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


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


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


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

old.setToggle_switch2 (data.getToggle_switch2());

old.setUrl_field(data.getUrl_field());

old.setUrl_field2(data.getUrl_field2());

old.setDecimal_field(data.getDecimal_field());

old.setDecimal_field2(data.getDecimal_field2());

old.setPercentage_field(data.getPercentage_field());

old.setPercentage_field2(data.getPercentage_field2());

old.setDocumentsequenc(data.getDocumentsequenc());

old.setRecaptcha(data.getRecaptcha());

old.setRecaptcha2(data.getRecaptcha2());

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






















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

	}}
