from datetime import date

from app.api.routes.admin_imports import (
    COL_ISSUE_DATE,
    COL_NAME,
    COL_PHONE,
    COL_PROJECT,
    date_is_valid,
    parse_issue_date,
    row_errors,
)


def test_parse_issue_date_accepts_common_formats():
    assert parse_issue_date("2026-06-01") == date(2026, 6, 1)
    assert parse_issue_date("2026/06/01") == date(2026, 6, 1)


def test_row_errors_require_project_code_to_exist():
    row = {
        COL_NAME: "张三",
        COL_PHONE: "13800000000",
        COL_PROJECT: "BAD",
        COL_ISSUE_DATE: "2026-06-01",
    }
    assert "Project code is inactive or missing" in row_errors(row, {"DBY"})


def test_date_is_valid_rejects_bad_text():
    assert not date_is_valid("not-a-date")
