package io.wdd.common.utils;

import io.wdd.server.beans.vo.ServerInfoVO;
import net.datafaker.Faker;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Locale;

@Component
public class FakeDataUtils {

    private static final String[] cityList = {"Tokyo Tokyo JP",
            "Phoenix Arizona US",
            "London England GB",
            "Seoul Seoul KR",
            "Shanghai Shanghai CN",
            "Tokyo Chiba JP"
    };
    private static final String[] archList = {
            "amd64",
            "arm64",
            "arm32",
            "xia32",
            "miples"
    };
    private static final String[] ipAddr = {
            "123.45.67.89",
            "98.76.54.32",
            "203.0.113.45",
            "87.65.43.21",
            "192.168.0.1",
            "203.0.113.99",
            "54.32.10.98",
            "123.123.123.123",
            "66.77.88.99",
            "203.0.113.200"
    };
    private static final String[] ipAddrV6 = {
            "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
            "2001:0db8:abcd:0123:4567:89ab:cdef:0123",
            "2001:0db8:0010:0000:0000:ff00:0042:8329",
            "2001:0db8:1234:5678:90ab:cdef:feeb:daed",
            "2001:0db8:dead:beef:cafe:babe:face:c0de",
            "2001:0db8:0012:3456:7890:abcd:ef01:2345",
            "2001:0db8:8765:4321:fedc:ba98:7654:3210",
            "2001:0db8:aaaa:bbbb:cccc:dddd:eeee:ffff",
            "2001:0db8:0000:1111:2222:3333:4444:5555",
            "2001:0db8:9999:8888:7777:6666:5555:4444"
    };

    public static final ServerInfoVO FakeServerInfo() {

        Faker faker = new Faker(new Locale(
                Locale.SIMPLIFIED_CHINESE.getLanguage(),
                Locale.SIMPLIFIED_CHINESE.getCountry()
        ));

        String machineId = faker.examplify("256035a5c78c434e8a33a5708ca46a64");

        String location = cityList[faker
                .random()
                .nextInt(cityList.length)];
        String arch = archList[faker
                .random()
                .nextInt(archList.length)];

        String cityName = location.split(" ")[0];
        String number = faker.numerify("08");

        String serverName = String.join(
                "-",
                cityName,
                arch,
                number
        );

        String agentTopicName = serverName + "-" + machineId.substring(
                0,
                6
        );


        String publicIpV4 = ipAddr[faker
                .random()
                .nextInt(ipAddr.length)];

        String publicIpV6 = ipAddrV6[faker
                .random()
                .nextInt(ipAddrV6.length)];

        ServerInfoVO serverInfoVO = ServerInfoVO
                .builder()
                .topicName(agentTopicName)
                .serverName(serverName)
                .serverIpPbV4(publicIpV4)
                .serverIpPbV6(publicIpV6)
                .location(location)
                .cpuBrand("AMD EPYC 7551 32-Core Processor")
                .cpuCore("1 @ 2400.010 MHz")
                .osInfo("Ubuntu 22.04.1 LTS")
                .osKernelInfo("5.15.0-1027-oracle")
                .comment(faker
                                 .artist()
                                 .name())
                .machineId(machineId)
                .build();


        return serverInfoVO;
    }

    @Bean(name = "fakerInstance")
    public Faker NewFakerInstance() {
        Faker faker = new Faker(new Locale(
                Locale.SIMPLIFIED_CHINESE.getLanguage(),
                Locale.SIMPLIFIED_CHINESE.getCountry()
        ));

        return faker;
    }
}
