package com.zcloud.personnel.positioning.command;

import com.zcloud.personnel.positioning.persistence.dataobject.CorpInfoSnapshotDO;
import com.zcloud.personnel.positioning.persistence.repository.PersonnelMatchRepository;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

class FindsPersonCorpResolverTest {

    @Test
    void ambiguousHighPriorityMatchDoesNotFallBackToLowerPriorityFields() {
        PersonnelMatchRepository repository = mock(PersonnelMatchRepository.class);
        when(repository.listMatchedPersonCompanies(anyMap()))
                .thenReturn(Arrays.asList(company("C1"), company("C2")));
        FindsPersonCorpResolver resolver = new FindsPersonCorpResolver(repository);

        FindsCorpMappingService.CorpMatch result = resolver.resolve(
                "ID-AMBIGUOUS", "F001", "测试人员", "T001");

        assertNull(result);
        verify(repository, never()).listLocalPersonCompanies(anyMap());
        verify(repository, never()).listTerminalCompanies("T001");
    }

    private CorpInfoSnapshotDO company(String id) {
        CorpInfoSnapshotDO company = new CorpInfoSnapshotDO();
        company.setCorpinfoId(id);
        company.setCorpName("公司" + id);
        return company;
    }
}
