import enum

from sqlalchemy import Boolean, Integer, String
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import BaseModel


class MemberLevel(BaseModel):
    """会员等级配置表。后台可配置多级会员权益。"""

    __tablename__ = "member_levels"

    name: Mapped[str] = mapped_column(String(50), nullable=False, comment="等级名称，如：普通会员、黄金会员")
    level: Mapped[int] = mapped_column(Integer, nullable=False, unique=True, index=True, comment="等级序号，1=最低")
    min_total_spent: Mapped[int] = mapped_column(
        Integer, default=0, nullable=False, comment="升级所需累计消费金额，单位分"
    )
    self_discount_rate: Mapped[int] = mapped_column(
        Integer, default=10000, nullable=False, comment="自购折扣率，万分比，10000=原价"
    )
    points_multiplier: Mapped[int] = mapped_column(
        Integer, default=10000, nullable=False, comment="积分倍率，万分比，10000=1.0x"
    )
    points_cashback_rate: Mapped[int] = mapped_column(
        Integer, default=0, nullable=False, comment="自购积分返现比例，万分比，如500=5%"
    )
    max_points_discount_rate: Mapped[int] = mapped_column(
        Integer, default=1000, nullable=False, comment="积分抵扣上限，万分比，如3500=35%"
    )
    can_apply_agent: Mapped[bool] = mapped_column(
        Boolean, default=False, nullable=False, comment="是否允许申请代理"
    )
    commission_rate: Mapped[int] = mapped_column(
        Integer, default=0, nullable=False, comment="会员返佣比例，万分比，如 500=5%"
    )
    sort_order: Mapped[int] = mapped_column(Integer, default=0, nullable=False, comment="排序权重")
    enabled: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False, comment="是否启用")
