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

"""
脚本项目数据模型
管理脚本项目的基本信息和目录结构
"""

from sqlalchemy import Column, Integer, String, DateTime, Text, Boolean
from sqlalchemy.sql import func
from .base import Base


class VWEDScriptProject(Base):
    """脚本项目模型"""
    
    __tablename__ = 'vwed_script_project'
    
    id = Column(Integer, primary_key=True, autoincrement=True, comment='项目ID')
    project_name = Column(String(100), nullable=False, comment='项目名称')
    project_path = Column(String(500), nullable=False, unique=True, comment='项目路径')
    description = Column(Text, comment='项目描述')
    status = Column(String(20), nullable=False, default='active', comment='项目状态: active, archived, deleted')
    created_by = Column(String(100), comment='创建者')
    created_at = Column(DateTime, nullable=False, default=func.now(), comment='创建时间')
    updated_at = Column(DateTime, nullable=False, default=func.now(), onupdate=func.now(), comment='更新时间')
    
    def __repr__(self):
        return f"<VWEDScriptProject(id={self.id}, name='{self.project_name}', path='{self.project_path}')>"
    
    def to_dict(self):
        """转换为字典格式"""
        return {
            'id': self.id,
            'project_name': self.project_name,
            'project_path': self.project_path,
            'description': self.description,
            'status': self.status,
            'created_by': self.created_by,
            'created_at': self.created_at.isoformat() if self.created_at else None,
            'updated_at': self.updated_at.isoformat() if self.updated_at else None,
        }