package com.ga.api.transfer;

import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 은행코드 → BankTransferFileGenerator 조회 팩토리.
 * 등록되지 않은 은행코드는 GENERIC_CSV 기본 생성기로 폴백.
 */
@Component
public class BankTransferFactory {

    private final Map<String, BankTransferFileGenerator> generators;

    public BankTransferFactory(List<BankTransferFileGenerator> list) {
        this.generators = list.stream()
                .collect(Collectors.toMap(BankTransferFileGenerator::getBankCode, Function.identity()));
    }

    public BankTransferFileGenerator get(String bankCode) {
        return generators.getOrDefault(bankCode, generators.get("GENERIC_CSV"));
    }
}
