package com.realnet.vpspack.Services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.realnet.realm.Entity.Realm;
import com.realnet.realm.Services.RealmService;
import com.realnet.users.entity1.AppUser;
import com.realnet.users.service1.AppUserServiceImpl;
import com.realnet.vpspack.Entity.Visa_processing;
import com.realnet.vpspack.Repository.Visa_processingRepository;

@Service
public class Visa_processingService {
	@Autowired
	private Visa_processingRepository Repository;
	@Autowired
	private AppUserServiceImpl userService;
	@Autowired
	private RealmService realmService;

	public Visa_processing Savedata(Visa_processing data) {

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

//	get all with pagination
	public Page<Visa_processing> getAllWithPagination(Pageable page) {
		return Repository.findAll(page, getUser().getUserId());
	}

	public List<Visa_processing> getdetails() {
		List<Realm> realm = realmService.findByUserId(getUser().getUserId());
		List<Visa_processing> all = Repository.findAll(getUser().getUserId());

		return all;
	}

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

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

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

		old.setDescription(data.getDescription());

		old.setActive(data.isActive());

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

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

	}
}
