package com.realnet.badmintoncourt.Services;
import com.realnet.badmintoncourt.Repository.Badminton_courtRepository;
import com.realnet.badmintoncourt.Entity.Badminton_court
;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 Badminton_courtService {
@Autowired
private Badminton_courtRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;





public Badminton_court Savedata(Badminton_court data) {






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


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


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


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


public Badminton_court update(Badminton_court data,Integer id) {
	Badminton_court old = Repository.findById(id).get();
old.setCourt_name(data.getCourt_name());

old.setDescription(data.getDescription());

old.setActive (data.getActive());

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






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

	}}
