from tortoise import fields
from app.models.base import TimestampMixin, BaseModel


class CleaningTask(BaseModel, TimestampMixin):
    target = fields.CharField(max_length=255, description="目标(URL/公司名/ID)")
    clean_type = fields.CharField(max_length=50, default="auto", description="清洗模式")
    platform = fields.CharField(max_length=50, default="auto", description="目标平台")
    proxy = fields.CharField(max_length=255, null=True, description="代理地址")
    status = fields.CharField(max_length=20, default="pending", description="状态: pending/processing/success/fail")
    storage_status = fields.CharField(max_length=20, default="unknown", description="存储状态: saved/duplicate/failed/unknown")
    remote_sent = fields.BooleanField(default=False, description="是否已远程推送")
    result_summary = fields.JSONField(null=True, description="清洗结果摘要")
    original_data = fields.JSONField(null=True, description="原始请求数据")
    error_msg = fields.TextField(null=True, description="错误信息")

    class Meta:
        table = "cleaning_task"


class ProxyConfig(BaseModel, TimestampMixin):
    name = fields.CharField(max_length=100, description="名称")
    proxy_type = fields.CharField(max_length=20, description="代理类型: http/socks/tunnel")
    platform = fields.CharField(max_length=50, default="all", description="目标平台: boss/qcwy/zhilian/all")
    proxy_url = fields.CharField(max_length=255, description="代理地址")
    is_active = fields.BooleanField(default=True, description="是否可用")

    class Meta:
        table = "proxy_config"


class ProxyProvider(BaseModel, TimestampMixin):
    name = fields.CharField(max_length=100, description="名称")
    platform = fields.CharField(max_length=50, default="all", description="目标平台: boss/qcwy/zhilian/all")
    mode = fields.CharField(max_length=20, description="解析模式: json/text")
    list_path = fields.CharField(max_length=255, null=True, description="JSON列表路径")
    ip_path = fields.CharField(max_length=255, null=True, description="IP字段路径")
    port_path = fields.CharField(max_length=255, null=True, description="端口字段路径")
    username_path = fields.CharField(max_length=255, null=True, description="用户名字段路径")
    password_path = fields.CharField(max_length=255, null=True, description="密码字段路径")
    pattern = fields.TextField(null=True, description="文本解析正则")
    template = fields.CharField(max_length=255, description="最终代理模板")

    class Meta:
        table = "proxy_provider"
