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























public Student_info Savedata(Student_info data) {
























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


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


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


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


public Student_info update(Student_info data,Integer id) {
	Student_info old = Repository.findById(id).get();
old.setStudent_name(data.getStudent_name());

old.setAddress(data.getAddress());

old.setPhone_number(data.getPhone_number());

old.setEmail_field(data.getEmail_field());

old.setPassword_field(data.getPassword_field());

old.setPercentage_field(data.getPercentage_field());

old.setIs_active (data.getIs_active());

old.setGender(data.getGender());

 

old.setDistric(data.getDistric());

old.setQrcode_field(data.getQrcode_field());

old.setCurrency(data.getCurrency());

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
























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

	}}
