package com.zioinfo.hrm.uiws.system.service;

import com.zioinfo.hrm.uiws.system.dto.PublicCompanyDto;
import com.zioinfo.hrm.uiws.system.dto.PublicDeptDto;
import com.zioinfo.hrm.uiws.system.mapper.CompanyMapper;
import com.zioinfo.hrm.uiws.system.mapper.DeptMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 가입 화면(비인증) 공개 조회. use_yn='Y' 부서/거래처만 노출.
 * (가입 시 존재하지 않는 FK 입력 → 오류 방지)
 */
@Service
@RequiredArgsConstructor
public class PublicLookupService {

    private final DeptMapper deptMapper;
    private final CompanyMapper companyMapper;

    @Transactional(readOnly = true)
    public List<PublicDeptDto> depts() {
        return deptMapper.findActiveOrdered().stream()
                .map(d -> new PublicDeptDto(d.getDeptId(), d.getDeptNm())).toList();
    }

    @Transactional(readOnly = true)
    public List<PublicCompanyDto> companies() {
        return companyMapper.findActiveOrdered().stream()
                .map(c -> new PublicCompanyDto(c.getCompanyId(), c.getCompanyNm())).toList();
    }
}
