package com.red.circle.order.infra.util;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 根据memberId生成固定的用户信息
 *
 * @author system
 */
public class MemberInfoGenerator {

    private static final String[] FIRST_NAMES = {
            // 男性名
            "James", "John", "Robert", "Michael", "William", "David", "Richard", "Joseph", "Thomas", "Charles",
            "Christopher", "Daniel", "Matthew", "Anthony", "Mark", "Donald", "Steven", "Paul", "Andrew", "Joshua",
            "Kenneth", "Kevin", "Brian", "George", "Timothy", "Ronald", "Edward", "Jason", "Jeffrey", "Ryan",
            "Jacob", "Gary", "Nicholas", "Eric", "Jonathan", "Stephen", "Larry", "Justin", "Scott", "Brandon",
            "Benjamin", "Samuel", "Raymond", "Gregory", "Frank", "Alexander", "Patrick", "Jack", "Dennis", "Jerry",
            // 女性名
            "Mary", "Patricia", "Jennifer", "Linda", "Elizabeth", "Barbara", "Susan", "Jessica", "Sarah", "Karen",
            "Lisa", "Nancy", "Betty", "Margaret", "Sandra", "Ashley", "Kimberly", "Emily", "Donna", "Michelle",
            "Dorothy", "Carol", "Amanda", "Melissa", "Deborah", "Stephanie", "Rebecca", "Sharon", "Laura", "Cynthia",
            "Kathleen", "Amy", "Angela", "Shirley", "Anna", "Brenda", "Pamela", "Emma", "Nicole", "Helen",
            "Samantha", "Katherine", "Christine", "Debra", "Rachel", "Carolyn", "Janet", "Catherine", "Maria", "Heather"
    };

    private static final String[] LAST_NAMES = {
            "Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis", "Rodriguez", "Martinez",
            "Hernandez", "Lopez", "Gonzalez", "Wilson", "Anderson", "Thomas", "Taylor", "Moore", "Jackson", "Martin",
            "Lee", "Perez", "Thompson", "White", "Harris", "Sanchez", "Clark", "Ramirez", "Lewis", "Robinson",
            "Walker", "Young", "Allen", "King", "Wright", "Scott", "Torres", "Nguyen", "Hill", "Flores",
            "Green", "Adams", "Nelson", "Baker", "Hall", "Rivera", "Campbell", "Mitchell", "Carter", "Roberts",
            "Turner", "Phillips", "Evans", "Parker", "Edwards", "Collins", "Stewart", "Morris", "Murphy", "Cook",
            "Rogers", "Morgan", "Peterson", "Cooper", "Reed", "Bailey", "Bell", "Gomez", "Kelly", "Howard",
            "Ward", "Cox", "Diaz", "Richardson", "Wood", "Watson", "Brooks", "Bennett", "Gray", "James",
            "Reyes", "Cruz", "Hughes", "Price", "Myers", "Long", "Foster", "Sanders", "Ross", "Morales",
            "Powell", "Sullivan", "Russell", "Ortiz", "Jenkins", "Gutierrez", "Perry", "Butler", "Barnes", "Fisher"
    };

    private static final String[] EMAIL_DOMAINS = {
            "gmail.com", "yahoo.com", "hotmail.com", "outlook.com", "icloud.com",
            "mail.com", "protonmail.com", "zoho.com", "aol.com", "yandex.com"
    };

    private static final String[] PHONE_PREFIXES = {
            "130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
            "150", "151", "152", "153", "155", "156", "157", "158", "159",
            "180", "181", "182", "183", "184", "185", "186", "187", "188", "189",
            "170", "171", "172", "173", "175", "176", "177", "178"
    };

    /**
     * 根据memberId生成固定的名（First Name）
     */
    public static String generateFirstName(String memberId) {
        int hash = Math.abs(memberId.hashCode());
        return FIRST_NAMES[hash % FIRST_NAMES.length];
    }

    /**
     * 根据memberId生成固定的姓（Last Name）
     */
    public static String generateLastName(String memberId) {
        int hash = Math.abs((memberId + "_last").hashCode());
        return LAST_NAMES[hash % LAST_NAMES.length];
    }

    /**
     * 根据memberId生成固定的中国手机号
     */
    public static String generatePhone(String memberId) {
        int hash = Math.abs(memberId.hashCode());
        String prefix = PHONE_PREFIXES[hash % PHONE_PREFIXES.length];

        // 用memberId的hashCode生成后8位，保证固定
        int suffix = Math.abs((memberId + "_phone").hashCode()) % 100000000;
        return prefix + String.format("%08d", suffix);
    }

    /**
     * 根据memberId生成固定的邮箱
     */
    public static String generateEmail(String memberId) {
        String firstName = generateFirstName(memberId).toLowerCase();
        String lastName = generateLastName(memberId).toLowerCase();

        int hash = Math.abs((memberId + "_email").hashCode());
        String domain = EMAIL_DOMAINS[hash % EMAIL_DOMAINS.length];

        // 生成数字后缀，保证唯一性
        int numSuffix = Math.abs((memberId + "_num").hashCode()) % 10000;

        return firstName + "." + lastName + numSuffix + "@" + domain;
    }

    /**
     * 一次性获取所有信息
     */
    public static MemberInfo generate(String memberId) {
        return new MemberInfo(
                generateFirstName(memberId),
                generateLastName(memberId),
                generatePhone(memberId),
                generateEmail(memberId)
        );
    }

    @Data
    @AllArgsConstructor
    public static class MemberInfo {
        /**
         * 名
         */
        private String firstName;

        /**
         * 姓
         */
        private String lastName;

        /**
         * 手机号
         */
        private String phone;

        /**
         * 邮箱
         */
        private String email;
    }
}
