from typing import Callable
from enum import IntEnum, StrEnum

import polars as pl


class HoldRangeType(IntEnum):
    """ 持有范围类型 """
    NUM = 1 # 按数量持有
    PCT = 2 # 按百分比持有
    

class HoldWeight(IntEnum):
    """ 持有权重 """
    NOTHOLD = 0 # 不持有
    AVG = 1 # 等权持有
    CLOSE= 2 # 按价格比例（等张）持有
    AMOUNT = 3 # 按成交量比例持有
    

class SortOrder(IntEnum):
    """ 排序方向 """
    ASCENDING = 0  # 升序
    DESCENDING = 1  # 降序


class SecurityPoolType(IntEnum):
    """标的池类型"""
    BUILTIN = 0, # 内置
    CUSTOMIZED = 1, # 自定义


class SecurityPoolCustomizeType(IntEnum):
    """标的池自定义类型"""
    FIXED = 0, # 固定标的池
    DYNAMIC_BY_FACTOR = 1, # 按照因子动态
    

class BuiltinScope(StrEnum):
    """ 内置范围 """
    process: Callable[[], pl.Expr]
    
    def __new__(cls, value: str, process: Callable[[], pl.Expr]) -> 'BuiltinScope':
        obj = str.__new__(cls, value)
        obj._value_ = value
        obj.process = process
        return obj
