package com.realnet.basicp1.Services;
import com.realnet.basicp1.Repository.ChildRepository;
import com.realnet.basicp1.Entity.Child;
 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.basicp1.Entity.Adv4;
import com.realnet.basicp1.Repository.Adv4Repository;
	import org.springframework.stereotype.Service;

@Service
 public class ChildUpdateService4 {
@Autowired
private ChildRepository Repository;
@Autowired
	private Adv4Repository adv4repository;


public  ResponseEntity<?>  updateaction(Integer id, Child child	) {
	Integer i = 0;	Adv4 adv4 = adv4repository.findById(id).get();
List<Child> list = new ArrayList<>();

		Object ChildObject = adv4.getChild();

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

		old.setActive(child.getActive());
old.setDescription(child.getDescription());
old.setName(child.getName());
final Child childdata = Repository.save(old);
i++;}		 			return new ResponseEntity<>(i+" updated", HttpStatus.OK);
 }}