package com.realnet.angulardatatype.Services;
import com.realnet.angulardatatype.Repository.SupportRepository;
import com.realnet.angulardatatype.Entity.Support;
 import java.util.List;
import org.springframework.http.ResponseEntity;
import java.util.ArrayList;

import org.springframework.http.HttpStatus;

import org.springframework.beans.factory.annotation.Autowired;
import com.realnet.angulardatatype.Entity.Ad8;
import com.realnet.angulardatatype.Repository.Ad8Repository;
	import org.springframework.stereotype.Service;

@Service
 public class SupportUpdateService2 {
@Autowired
private SupportRepository Repository;
@Autowired
	private Ad8Repository ad8repository;


public  ResponseEntity<?>  updateaction(Integer id, Support support	) {
	Integer i = 0;	Ad8 ad8 = ad8repository.findById(id).get();
List<Support> list = new ArrayList<>();

		Object SupportObject = ad8.getSupport();

		if (SupportObject instanceof List<?>) {
			// If it's a list, cast and add all elements to the list
			list.addAll((List<Support>) SupportObject);
		} else if (SupportObject instanceof Support) {
			// If it's a single Childb object, add it to the list
			list.add((Support) SupportObject);
		}		for (Support li : list) {		Support old = Repository.findById(li.getId()).get();

		old.setDescription(support.getDescription());
old.setName(support.getName());
final Support supportdata = Repository.save(old);
i++;}		 			return new ResponseEntity<>(i+" updated", HttpStatus.OK);
 }}