from __future__ import annotations

from datetime import date
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from simorgh.apps.hr_core.models import Employee, EmployeeDocument


def add_employee_document(
    *,
    employee: "Employee",
    doc_type: str,
    dms_file_id: str,
    title: str = "",
    expiry_date: date | None = None,
) -> "EmployeeDocument":
    from simorgh.apps.hr_core.models import EmployeeDocument

    return EmployeeDocument.objects.create(
        tenant_id=employee.tenant_id,
        organization_node_id=employee.organization_node_id,
        employee=employee,
        doc_type=doc_type,
        dms_file_id=dms_file_id,
        title=title.strip(),
        expiry_date=expiry_date,
    )


def verify_employee_document(doc: "EmployeeDocument") -> "EmployeeDocument":
    doc.is_verified = True
    doc.save()
    return doc


def delete_employee_document(doc: "EmployeeDocument") -> None:
    doc.delete()
