using AyCode.Core.Consts;
using AyCode.Interfaces.Addresses;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Server.Logins;

namespace AyCode.Models.Server.Logins;

public class AcLoggedInModelServer<TUser, TUserToken, TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcLoggedInModelBase<TUser, TUserToken, TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
    
    where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
    where TUserToken : class, IAcUserTokenBase
    where TProfile : class, IAcProfile<TProfileAddress>
    where TCompany : class, IAcCompanyBase
    where TUserToServiceProvider : class, IAcUserToCompanyBase
    where TProfileAddress : class, IAcAddress
{
    public bool IsLoggedIn => LoggedInUser != null;

    public TUser LoggedInUser { get; private set; }
    public string AccessToken { get; private set; }
    public AcErrorCode LoginErrorCode { get; set; }

    public void AddLoggedInUser(TUser user, string accessToken)
    {
        LoggedInUser = user;
        AccessToken = accessToken;
    }

    public void Logout()
    {
        AccessToken = string.Empty;
        LoggedInUser = null;

        LoginErrorCode = AcErrorCode.Unset;
    }
}