package com.its.op.service.its.vms;

import com.its.op.dao.repository.its.vms.TbVmsFormObjectTypeRepository;
import com.its.op.dto.its.vms.TbVmsFormObjectTypeDto;
import com.its.op.entity.its.vms.TbVmsFormObjectType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RequiredArgsConstructor
@Service
public class TbVmsFormObjectTypeService {

    private final TbVmsFormObjectTypeRepository repo;

    // 전체 데이터 조회
    @Transactional(readOnly = true)
    public List<TbVmsFormObjectTypeDto> findAll() {
        List<TbVmsFormObjectTypeDto> result = new ArrayList<>();
        List<TbVmsFormObjectType> data = this.repo.findAll();
        data.forEach(obj -> {
            if (("Y").equals(obj.getUseYn())) {
                result.add(obj.toDto());
            }
        });
        return result;
    }

    /**
     * 폼 유형별 객체 목록 조회
     * @param type
     * @return
     */
    public List<TbVmsFormObjectTypeDto> findAllByFormType(Integer type) {
        List<TbVmsFormObjectTypeDto> result = new ArrayList<>();
        List<TbVmsFormObjectType> data = this.repo.findAllByFormType(type);
        data.forEach(obj -> {
            if (("Y").equals(obj.getUseYn())) {
                result.add(obj.toDto());
            }
        });
        return result;
    }
}
