import os
import random

from faker import Faker
from requests import post

from pctoken import get_token


BASE_URL = 'http://192.168.0.209:9999'
USERNAME = 'admin'
PASSWORD = '123456'

# TODO: 你自己处理
ORG_ID = ['2019668989619634177','2019669020191916033','2019669694686330882','2019669543792050177','2019669579221336066','2019669610317905922']

# 新增时一般传 "0"
PERSON_ID = '0'

# TODO: 如需绑定角色你自己填（int 列表）
ROLE_IDS = []

# 新增学生
CREATE_PERSON_API = '/admin/person-info'

fake = Faker('zh_CN')


def main() -> None:
	data = get_token(BASE_URL, USERNAME, PASSWORD)
	token = data.get('access_token', '')
	if not token:
		raise RuntimeError('No access_token found')

	headers = {
		'Authorization': f'Bearer {token}',
		'hx-client': 'hongxapp',
	}
	for _ in range(200):
		index = random.randint(0, 2)
		names = [fake.name(), fake.name_male(), fake.name_female()]
		fake_name = names[index]


		body = {
			'personId':0,
			'orgId': random.choice(ORG_ID),
			'postId': 0,
			'personType': 'hx_stud',
			'name': fake_name,
			'tel': fake.phone_number(),
			'gender':index,
			'idcard': fake.ssn(),
			'personCode': '',
			'status': random.choice(['0', '1']),
			'deptId': 0,
			'delFlag': '0',
			'avatar': '',
			'personUserModelList': [
				{
					'username': fake.user_name(),
					'relationType': '',
					'phone': fake.phone_number(),
					'password': '123456',
					'teamUserType': '',
					'personType': 'hx_stud',
					'personId': '0',
					'name': fake.user_name(),
					'key': '',
					'relId': 0,
					'roleIds': ['2015665758143623178'],
				},
			],
		}

		resp = post(BASE_URL + CREATE_PERSON_API, headers=headers, json=body, timeout=30)
		print(resp.status_code, resp.text)


if __name__ == '__main__':
	main()
