#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations


BROWSE_TYPE_SHOULD_READ = "应读"
BROWSE_TYPE_PRE_REG_UNREAD = "注册前未读"

_BROWSE_TYPES_ALLOWED_INPUT = {BROWSE_TYPE_SHOULD_READ, BROWSE_TYPE_PRE_REG_UNREAD}


def normalize_browse_type(value, default: str = BROWSE_TYPE_SHOULD_READ) -> str:
    text = str(value or "").strip()
    if text == BROWSE_TYPE_PRE_REG_UNREAD:
        return BROWSE_TYPE_PRE_REG_UNREAD
    if text == BROWSE_TYPE_SHOULD_READ:
        return BROWSE_TYPE_SHOULD_READ
    return default


def validate_browse_type(value, default: str = BROWSE_TYPE_SHOULD_READ):
    text = str(value if value is not None else default).strip()
    if text not in _BROWSE_TYPES_ALLOWED_INPUT:
        return None
    return normalize_browse_type(text, default=default)

