# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_requested_filings.ipynb.

# %% auto 0
__all__ = ['RequestedFilings']

# %% ../nbs/00_requested_filings.ipynb 1
import re
from dataclasses import dataclass

# %% ../nbs/00_requested_filings.ipynb 4
@dataclass
class RequestedFilings:
    ticker_or_cik: str
    form_type: str = "10-Q"
    limit: int = 1

    _REGEX_PATTERN = r"^(?:(\d+)/)?([^/]+)(?:/([^/]+))?$"

    @classmethod
    def from_string(cls, s: str):
        match = re.match(cls._REGEX_PATTERN, s.strip())
        if not match:
            raise ValueError(f"Invalid RequestedFilings string: {s}")
        limit_str, ticker_or_cik, form_type = match.groups()
        limit = int(limit_str) if limit_str else cls.limit
        form_type = form_type if form_type else cls.form_type
        form_type = form_type.upper()
        return cls(
            limit=limit,
            ticker_or_cik=ticker_or_cik,
            form_type=form_type,
        )
