package com.realnet.vpspack.Services;
import com.realnet.vpspack.Repository.Visa_app_orderRepository;
import com.realnet.vpspack.Entity.Visa_app_order
;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.vpspack.Entity.Visa_app_order;
import com.realnet.vpspack.Services.Visa_app_orderService;



	import org.springframework.stereotype.Service;

@Service
 public class Visa_app_orderService {
@Autowired
private Visa_app_orderRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;



@Autowired
	private Visa_app_orderService priceserv;

public Visa_app_order Savedata(Visa_app_order data) {





 
if (data.getPrice() != null) {
			Visa_app_order get =  priceserv.getdetailsbyId(data.getPrice());
			data.setPricename(get.getRate());

		}

 


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


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


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


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


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

old.setRate(data.getRate());

old.setPrice(data.getPrice());

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






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

	}}
