"""
测试数据生成器
"""

import random
import string
from faker import Faker


class DataGenerator:
    """测试数据生成器"""
    
    def __init__(self, locale: str = "zh_CN"):
        self.faker = Faker(locale)
    
    def generate_username(self) -> str:
        """生成用户名"""
        return f"testuser_{''.join(random.choices(string.ascii_lowercase + string.digits, k=8))}"
    
    def generate_password(self, length: int = 12) -> str:
        """生成密码"""
        chars = string.ascii_letters + string.digits + "!@#$%^&*"
        return ''.join(random.choices(chars, k=length))
    
    def generate_email(self) -> str:
        """生成邮箱"""
        return self.faker.email()
    
    def generate_phone(self) -> str:
        """生成手机号"""
        return self.faker.phone_number()
    
    def generate_name(self) -> str:
        """生成姓名"""
        return self.faker.name()
    
    def generate_role_name(self) -> str:
        """生成角色名"""
        return f"ROLE_{''.join(random.choices(string.ascii_uppercase, k=6))}"
    
    def generate_dict_type(self) -> str:
        """生成字典类型"""
        return f"DICT_TYPE_{''.join(random.choices(string.ascii_uppercase, k=4))}"
    
    def generate_dict_code(self) -> str:
        """生成字典编码"""
        return f"CODE_{''.join(random.choices(string.ascii_uppercase + string.digits, k=6))}"
    
    def generate_url(self) -> str:
        """生成URL"""
        return self.faker.url()
    
    def generate_company_name(self) -> str:
        """生成公司名"""
        return self.faker.company()
    
    def generate_address(self) -> str:
        """生成地址"""
        return self.faker.address()
    
    def generate_description(self) -> str:
        """生成描述"""
        return self.faker.text(max_nb_chars=200)
    
    def generate_permissions(self) -> str:
        """生成权限字符串"""
        permissions = ["READ", "WRITE", "DELETE", "ADMIN", "MANAGE"]
        selected = random.sample(permissions, random.randint(1, len(permissions)))
        return ",".join(selected)


data_generator = DataGenerator()
