package com.realnet.standardcontainer.Services;
import com.realnet.standardcontainer.Repository.Additional_containerRepository;
import com.realnet.standardcontainer.Entity.Additional_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 Additional_containerService {
@Autowired
private Additional_containerRepository Repository;
	@Autowired
	private AppUserServiceImpl userService; 
@Autowired
	private RealmService realmService;



















public Additional_container Savedata(Additional_container data) {




















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


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


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


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


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

old.setDescription(data.getDescription());

old.setActive (data.isActive());

old.setService_name(data.getService_name());

old.setPort_no(data.getPort_no());

old.setType(data.getType());

old.setImage_tag(data.getImage_tag());

old.setModel(data.getModel());

old.setDeployment(data.getDeployment());

old.setDeploy_app(data.getDeploy_app());

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




















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

	}}
