#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
扩展属性数据模型
用于存储动作点的扩展属性定义
"""

from sqlalchemy import Column, String, Text, Boolean, Integer, Enum
from sqlalchemy.dialects.mysql import VARCHAR
from data.models.base import BaseModel
from enum import Enum as PyEnum


class ExtendedPropertyTypeEnum(PyEnum):
    """扩展属性类型枚举"""
    STRING = "string"         # 字符串
    INTEGER = "integer"       # 整数
    FLOAT = "float"          # 浮点数
    BOOLEAN = "boolean"       # 布尔值
    DATE = "date"            # 日期
    DATETIME = "datetime"     # 日期时间
    TEXT = "text"            # 长文本
    SELECT = "select"        # 下拉选择
    MULTISELECT = "multiselect"  # 多选


class ExtendedProperty(BaseModel):
    """扩展属性模型"""
    
    __tablename__ = "extended_properties"
    
    # 基本信息
    property_key = Column(VARCHAR(200),nullable=False, index=True, comment="属性键（与属性名称相同）")
    property_name = Column(VARCHAR(200), nullable=False, index=True, comment="属性名称（唯一标识）")
    property_type = Column(Enum(ExtendedPropertyTypeEnum), nullable=False, comment="属性类型")
    
    # 属性设置
    is_required = Column(Boolean, default=False, comment="是否必填")
    is_enabled = Column(Boolean, default=True, comment="是否启用")
    
    # 描述信息
    description = Column(Text, comment="属性描述")
    placeholder = Column(VARCHAR(500), comment="输入提示")
    
    # 默认值和选项
    default_value = Column(Text, comment="默认值")
    options = Column(Text, comment="选项值（JSON格式，用于select和multiselect类型）")
    
    # 验证规则
    validation_rules = Column(Text, comment="验证规则（JSON格式）")
    
    # 分类和排序
    category = Column(VARCHAR(100), comment="属性分类")
    sort_order = Column(Integer, default=0, comment="排序顺序")
    
    # 显示设置
    display_width = Column(Integer, default=200, comment="显示宽度（像素）")
    display_format = Column(VARCHAR(100), comment="显示格式")
    
    def __repr__(self):
        return f"<ExtendedProperty(property_key='{self.property_key}', property_name='{self.property_name}', property_type='{self.property_type}')>" 