CREATE PROCEDURE [REG_GetUsers]
	@UserId BIGINT = NULL,
	@UserTypeId TINYINT = NULL
AS
	SELECT Users.UserId, UserRoleId, ApiConsumerId, Email, UserTypeId, UserName, FirstName, LastName, CountryId, PhonePrefix, Phone, Address, City,
    ZipCode, BirthDate, Gender, LanguageId, IsUSTaxEntity, RegistrationDate, KYC_Approved, CreateDate, CreateOrigin, CreateIPAddress, Source, LastModifyDate,
    LastModifyOrigin, LastModifyOperatorId, TermsOfServiceChecked, MailVerfied, PhoneVerified, HasAvatar, [Rank],
	CAST((CASE WHEN EXISTS(SELECT 1 FROM Signals WHERE CreatorUserId = Users.UserId) THEN 1 ELSE 0 END) AS bit) AS UserIsKnokser,
	ISNULL(follow.UserFollowers, 0) CountFollowers
	FROM Users with(nolock)
	LEFT JOIN (select count(f.UserId) UserFollowers, f.FollowUserId userId from [dbo].[UserFollows] f group by f.FollowUserId) follow on follow.userId = users.UserId
	WHERE Users.UserId = ISNULL(@UserId, Users.UserId)
	AND UserTypeId = ISNULL(@UserTypeId, UserTypeId)
RETURN 0
