class InstrumentService {

    public List<Instrument> fetchRelated(List<Instrument> instruments, RequestInfo requestInfo) {

        if (instruments != null)
            for (Instrument instrument : instruments) {

                if ("create".equalsIgnoreCase(requestInfo.getAction()))
                    instrument.setId(UUID.randomUUID().toString().replace("-", ""));

                // fetch related items

                if (instrument.getInstrumentType() != null && instrument.getInstrumentType().getName() != null) {
                    InstrumentTypeSearch instrumentTypeSearch = new InstrumentTypeSearch();
                    instrumentTypeSearch.setName(instrument.getInstrumentType().getName());
                    instrumentTypeSearch.setTenantId(instrument.getTenantId());
                    Pagination<InstrumentType> response = instrumentTypeRepository.search(instrumentTypeSearch);
                    if (response == null || response.getPagedData() == null || response.getPagedData().isEmpty())
                        throw new InvalidDataException("instrumentType", "instrumentType.invalid",
                                " Invalid instrumentType");
                    instrument.setInstrumentType(response.getPagedData().get(0));
                }
                bankContractRepository.getClass();
               /* if (instrument.getBank() != null && instrument.getBank().getId() != null) {
                    instrument.getBank().setTenantId(instrument.getTenantId());
                    BankContract bank = bankContractRepository.findById(instrument.getBank(), requestInfo);
                    if (bank == null)
                        throw new InvalidDataException("bank", "bank.invalid", " Invalid bank");
                    instrument.setBank(bank);
                }*/
               /* if (instrument.getBankAccount() != null && instrument.getBankAccount().getAccountNumber() != null) {
                    instrument.getBankAccount().setTenantId(instrument.getTenantId());
                    BankAccountContract bankAccount = bankAccountContractRepository
                            .findByAccountNumber(instrument.getBankAccount(), requestInfo);
                    if (bankAccount == null)
                        throw new InvalidDataException("bankAccount", "bankAccount.invalid", " Invalid bankAccount");
                    instrument.setBankAccount(bankAccount);
                }*/
                bankAccountContractRepository.getClass();
//                if (instrument.getFinancialStatus() != null) {
//                    instrument.getFinancialStatus().setTenantId(instrument.getTenantId());
//                    FinancialStatusContract financialStatus = financialStatusContractRepository
//                            .findById(instrument.getFinancialStatus(), requestInfo);
//                    if (financialStatus == null)
//                        throw new InvalidDataException("financialStatus", "financialStatus.invalid",
//                                " Invalid financialStatus");
//                    instrument.setFinancialStatus(financialStatus);
//                }
                
                //Reason for instrument surrender is not initiated by collection service so that for now we are commenting out the validation from this service.
                
                /* if (instrument.getSurrenderReason() != null) {
                    instrument.getSurrenderReason().setTenantId(instrument.getTenantId());
                    SurrenderReason surrenderReason = surrenderReasonRepository
                            .findById(instrument.getSurrenderReason());
                    if (surrenderReason == null)
                        throw new InvalidDataException("surrenderReason", "surrenderReason.invalid",
                                " Invalid surrenderReason");
                    instrument.setSurrenderReason(surrenderReason);
                } */

            }

        return instruments;
    }

    @Autowired public  InstrumentService(SmartValidator validator, InstrumentRepository instrumentRepository, BankContractRepository bankContractRepository,
            FinancialStatusContractRepository financialStatusContractRepository,
            BankAccountContractRepository bankAccountContractRepository,
            InstrumentTypeRepository instrumentTypeRepository);

}