package com.realnet.angulardatatype.Services;
import com.realnet.angulardatatype.Repository.Basicp2Repository;
import com.realnet.angulardatatype.Entity.Basicp2
;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 org.springframework.stereotype.Service;

@Service
 public class Basicp2Service {
@Autowired
private Basicp2Repository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;

















public Basicp2 Savedata(Basicp2 data) {
















data.setUser_id(getUser().getUserId());
		data.setUser_name(getUser().getFullName());

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


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


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


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


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

old.setTextarea2(data.getTextarea2());

old.setDate_field(data.getDate_field());

old.setDate_field2(data.getDate_field2());

old.setDatetime_field(data.getDatetime_field());

old.setDatetime_field2(data.getDatetime_field2());

old.setEmail_field(data.getEmail_field());

old.setEmail_field2(data.getEmail_field2());



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


















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

	}}
