package com.realnet.deploy_container.Services;
import com.realnet.deploy_container.Repository.Deployed_containerRepository;
import com.realnet.deploy_container.Entity.Deployed_container
;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 Deployed_containerService {
@Autowired
private Deployed_containerRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;









public Deployed_container Savedata(Deployed_container data) {










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


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


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


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


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

old.setDescription(data.getDescription());

old.setActive (data.isActive());

old.setProject_id(data.getProject_id());

old.setWorkflow_id(data.getWorkflow_id());

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










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

	}}
