from __future__ import annotations

import hashlib

from app.models.employee import Employee

DEFAULT_EMPLOYEE_BANK_NAME = "招商银行深圳科技园支行"


def build_default_bank_account_no(employee_no: str | None) -> str | None:
    text = str(employee_no or "").strip()
    if not text:
        return None

    digest = hashlib.sha256(text.encode("utf-8")).hexdigest()
    numeric = str(int(digest[:18], 16)).zfill(13)[-13:]
    return f"622588{numeric}"


def apply_default_bank_info(employee: Employee) -> None:
    if not employee.bank_account_name and employee.name:
        employee.bank_account_name = employee.name
    if not employee.bank_name:
        employee.bank_name = DEFAULT_EMPLOYEE_BANK_NAME
    if not employee.bank_account_no:
        employee.bank_account_no = build_default_bank_account_no(employee.employee_no)
