package com.realnet.order_estimation.Services;
import com.realnet.order_estimation.Repository.Customer_informationRepository;
import com.realnet.order_estimation.Entity.Customer_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 com.realnet.order_estimation.Entity.Customer_information;

import com.realnet.order_estimation.Repository.Customer_informationRepository;


	import org.springframework.stereotype.Service;

@Service
 public class Customer_informationService {
@Autowired
private Customer_informationRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;















public Customer_information Savedata(Customer_information data) {
















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


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


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


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


public Customer_information update(Customer_information data,Integer id) {
	Customer_information old = Repository.findById(id).get();
old.setCustomer_name(data.getCustomer_name());

old.setContact_person(data.getContact_person());

old.setEmail_address(data.getEmail_address());

old.setPhone_number(data.getPhone_number());

old.setCustomer_address(data.getCustomer_address());

old.setDeployment_type(data.getDeployment_type());

  
 
old.setUps_monitoring(data.isUps_monitoring());
   

 
old.setActive_energy(data.isActive_energy());
   

 
old.setDg_monitoring_with_fuel(data.isDg_monitoring_with_fuel());
   

 
old.setDg_monitoring_without_fuel(data.isDg_monitoring_without_fuel());
   

 
old.setApfc_panel_monitoring(data.isApfc_panel_monitoring());
   

 
old.setBusbar_monitoring(data.isBusbar_monitoring());
   

 
old.setWater_management_stp_etp(data.isWater_management_stp_etp());
   

 
old.setLt_panel_monitoring(data.isLt_panel_monitoring());
   

 
old.setHt_panel_monitoring(data.isHt_panel_monitoring());
   

 
old.setCompressed_air__gas_monitoring(data.isCompressed_air__gas_monitoring());
   

 
old.setCompressed_air_lpg_o2_n2_co2(data.isCompressed_air_lpg_o2_n2_co2());
   

 
old.setWater_management_water_monitoring(data.isWater_management_water_monitoring());
   


  



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















//	Insert Action

	@Autowired
	private Customer_informationRepository customer_informationinsertrepository;

public Customer_information insertCustomer_information(Customer_information data) {

data.setUpdatedBy(getUser().getUserId());
		data.setCreatedBy(getUser().getUserId());
		data.setAccountId(getUser().getAccount().getAccount_id());


		final Customer_information save = customer_informationinsertrepository.save(data);
		return save;
	}

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

	}}
