package com.realnet.angulardatatype.Services;
import com.realnet.stpkg.Repository.ChildformRepository;
import com.realnet.stpkg.Entity.Childform;
 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 ChildformUpdateService3 {
@Autowired
private ChildformRepository Repository;
@Autowired
	private Ad8Repository ad8repository;


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

		Object ChildformObject = ad8.getChildform();

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

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