package com.realnet.basic.Services;
import com.realnet.basic.Repository.Dashboard_overviewRepository;
import com.realnet.basic.Entity.Dashboard_overview
;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 Dashboard_overviewService {
@Autowired
private Dashboard_overviewRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;









public Dashboard_overview Savedata(Dashboard_overview data) {










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


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


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


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


public Dashboard_overview update(Dashboard_overview data,Integer id) {
	Dashboard_overview old = Repository.findById(id).get();
old.setTotal_clients(data.getTotal_clients());

old.setActive_projects(data.getActive_projects());

old.setTotal_revenue(data.getTotal_revenue());

old.setRecent_clients(data.getRecent_clients());

old.setRecent_projects(data.getRecent_projects());

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










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

	}}
