"""Deterministic ID generators for ACE-F entities."""
from __future__ import annotations

import hashlib
import uuid


def document_id(source: str, issuer_id: str, date: str, accession: str) -> str:
    """DOC::{source}::{issuer_id}::{date}::{accession}"""
    return f"DOC::{source}::{issuer_id}::{date}::{accession}"


def event_id(document_id_str: str, event_type: str, sequence: int = 0) -> str:
    """EVT::{document_id}::{event_type}::{sequence}"""
    return f"EVT::{document_id_str}::{event_type}::{sequence}"


def issuer_id_from_cik(cik: str) -> str:
    return f"ISSUER::{cik.lstrip('0').zfill(10)}"


def symbol_id_from_ticker(ticker: str, venue: str = "XNYS") -> str:
    return f"SYM::{ticker.upper()}::{venue}"


def new_job_run_id() -> str:
    return str(uuid.uuid4())


def sha256_checksum(content: bytes) -> str:
    return hashlib.sha256(content).hexdigest()


def sha256_checksum_str(content: str) -> str:
    return sha256_checksum(content.encode("utf-8"))
