getBody(), true) ?: []; $companyId = (int) ($body['company_id'] ?? 0); $name = $body['name'] ?? $body['user_name'] ?? null; $phone = $body['phone'] ?? $body['user_phone'] ?? ''; $email = $body['email'] ?? $body['user_email'] ?? ''; $role = $body['role'] ?? $body['user_role'] ?? ''; $password = $body['password'] ?? ''; if ($companyId <= 0 || empty($phone) || empty($email) || empty($role) || empty($password)) { return ResponseLib::sendFail("Missing company_id, phone, email, role or password", [], "E_VALIDATE")->withStatus(400); } if (strlen($password) < 8) { return ResponseLib::sendFail("Password must be at least 8 characters", [], "E_VALIDATE")->withStatus(400); } $userModel = new UserModel(); $userData = $userModel->createUser($companyId, $email, $password, $phone, $role, $name); if (!$userData) { return ResponseLib::sendFail("Email already exists, company not found, or creation failed", [], "E_VALIDATE")->withStatus(400); } return ResponseLib::sendOk($userData, "S_CREATED"); } }