using System;
using VCommon.VApplication.Authorization;

namespace VCommon.VApplication
{
    public interface IVSession
    {
        Guid? UserId { get; }
        Guid? TenantId { get; }

        string Token { get; }

        void DemandAuth();

        public Guid GetUserId()
        {
            if (!UserId.HasValue) throw new VApplicationAuthException("UserId is null! Probably, user is not logged in.", AuthReason.AuthRequired);
            return UserId.Value;
        }

        public Guid GetTenantId()
        {
            if (!TenantId.HasValue)
                throw new VApplicationAuthException("TenantId is null! Possible problems: No user logged in or current logged in user in a host user (TenantId is always null for host users).", AuthReason.AuthRequired);
            return TenantId.Value;
        }

        public MultiTenancySides Side => TenantId.HasValue ? MultiTenancySides.Tenant : MultiTenancySides.Host;

        void Refresh();
    }
}
