package com.realnet.taxi_rental.Services;
import com.realnet.taxi_rental.Repository.Vehicle_add_onRepository;
import com.realnet.taxi_rental.Entity.Vehicle_add_on
;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 Vehicle_add_onService {
@Autowired
private Vehicle_add_onRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;











public Vehicle_add_on Savedata(Vehicle_add_on data) {












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


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


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


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


public Vehicle_add_on update(Vehicle_add_on data,Integer id) {
	Vehicle_add_on old = Repository.findById(id).get();
old.setName(data.getName());

old.setDescription(data.getDescription());

old.setActive (data.getActive());

old.setIcon(data.getIcon());

old.setPrice_per_day(data.getPrice_per_day());

old.setPrice_per_trip(data.getPrice_per_trip());

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












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

	}}
