## MODIFIED Requirements

### Requirement: Position Resolution in Employee Import
For each row, the system SHALL resolve one position from "Vị trí", narrowed by the company scope and, when filled, by "Phòng ban". The company scope SHALL be:
- when `company_mode` is a specific company X: company X;
- when `company_mode` is `all` and "Công ty" is filled: every company whose name equals "Công ty";
- when `company_mode` is `all` and "Công ty" is blank: all companies.

After narrowing, when more than one position remains:
- if "Phòng ban" is blank and the remaining positions belong to departments with different names, the row SHALL be rejected with reason code `position_ambiguous` and a message asking to fill "Phòng ban";
- otherwise, if the company scope is all companies and the remaining positions belong to companies with different names, the row SHALL be rejected with reason code `position_ambiguous` and a message asking to fill "Công ty";
- otherwise, all remaining positions have the same position, department and company names, and the system SHALL take the one with the lowest id.

The employee's department, company, default leader and the company used for annual-leave conversion SHALL be derived from the resolved position. The system SHALL NOT fall back to a default position.

#### Scenario: Same position name in two departments, disambiguated by department
- **WHEN** positions named "Developer" exist in department "Web" and in department "Game", and an admin imports two rows with "Vị trí" = "Developer" and "Phòng ban" = "Web" and "Game" respectively
- **THEN** the first employee is assigned the "Developer" position of department "Web"
- **AND** the second employee is assigned the "Developer" position of department "Game"

#### Scenario: Same position name in two companies, disambiguated by company
- **WHEN** positions named "Accountant" exist in company "TAT" and company "Suga", `company_mode` is `all`, and a row has "Vị trí" = "Accountant" and "Công ty" = "Suga"
- **THEN** the employee is assigned the "Accountant" position of company "Suga"

#### Scenario: Unique position name without department or company
- **WHEN** exactly one position named "CEO (TAT)" exists within the company scope and a row has "Vị trí" = "CEO (TAT)" with blank "Phòng ban" and "Công ty"
- **THEN** the employee is assigned that position

#### Scenario: Ambiguous position, department missing
- **WHEN** positions named "Developer" exist in departments "Web" and "Game" within the company scope and a row has "Vị trí" = "Developer" with blank "Phòng ban"
- **THEN** the row is not imported
- **AND** the row is reported with reason code `position_ambiguous` and a message asking to fill "Phòng ban"

#### Scenario: Same department name in two companies, company missing
- **WHEN** `company_mode` is `all`, positions named "Sale" exist in a department named "Sales" of company "TAT" and of company "Suga", and a row has "Vị trí" = "Sale", "Phòng ban" = "Sales" and blank "Công ty"
- **THEN** the row is not imported
- **AND** the row is reported with reason code `position_ambiguous` and a message asking to fill "Công ty"

#### Scenario: Identical position, department and company names
- **WHEN** two departments named "Sales" exist in the same company, each with a position named "Sale", and a row resolves to both of them
- **THEN** the employee is assigned the "Sale" position with the lowest id

#### Scenario: Companies with the same name
- **WHEN** `company_mode` is `all`, two companies are named "Suga", and a row has "Công ty" = "Suga"
- **THEN** positions of both companies are candidates
- **AND** the row is resolved by the rules above instead of being rejected for the company name

#### Scenario: Position not found
- **WHEN** no position matches "Vị trí" within the company scope and the department filter
- **THEN** the row is not imported
- **AND** the row is reported with reason code `position_not_found`

#### Scenario: Blank position
- **WHEN** a row has a blank "Vị trí"
- **THEN** the row is not imported
- **AND** the row is reported with reason code `position_required`

#### Scenario: Specific company mode scopes the lookup
- **WHEN** `company_mode` is company X, a row has blank "Công ty", and "Vị trí" matches exactly one position in company X and other positions in other companies
- **THEN** the employee is assigned the position in company X

#### Scenario: Specific company mode with a different company in the file
- **WHEN** `company_mode` is company X and a row has "Công ty" filled with a name other than company X's name
- **THEN** the row is not imported
- **AND** the row is reported with reason code `company_mismatch`

#### Scenario: Unknown company name in all mode
- **WHEN** `company_mode` is `all` and "Công ty" does not match any company name
- **THEN** the row is not imported
- **AND** the row is reported with reason code `company_not_found`
