package com.realnet.basicp1.Services;
import com.realnet.basicp1.Repository.Personal_informationRepository;
import com.realnet.basicp1.Entity.Personal_information
;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 Personal_informationService {
@Autowired
private Personal_informationRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;

















public Personal_information Savedata(Personal_information data) {


















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


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


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


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


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

old.setTitle(data.getTitle());

old.setCompany(data.getCompany());

 

old.setEmail_field(data.getEmail_field());

old.setPhone_number(data.getPhone_number());

old.setWebsite(data.getWebsite());

old.setLinkedin(data.getLinkedin());

old.setTwitter(data.getTwitter());

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


















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

	}}
