using System.Collections.Generic;
using System.Runtime.Serialization;

namespace KeycloakDemo
{
    /// <summary>
    /// 用户信息模型
    /// 从 id_token 或 userinfo 端点获取
    /// </summary>
    [DataContract]
    public class UserInfo
    {
        /// <summary>
        /// 用户唯一标识 (Subject)
        /// </summary>
        [DataMember(Name = "sub")]
        public string Subject { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [DataMember(Name = "preferred_username")]
        public string Username { get; set; }

        /// <summary>
        /// 显示名称
        /// </summary>
        [DataMember(Name = "name")]
        public string Name { get; set; }

        /// <summary>
        /// 名
        /// </summary>
        [DataMember(Name = "given_name")]
        public string GivenName { get; set; }

        /// <summary>
        /// 姓
        /// </summary>
        [DataMember(Name = "family_name")]
        public string FamilyName { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [DataMember(Name = "email")]
        public string Email { get; set; }

        /// <summary>
        /// 邮箱是否已验证
        /// </summary>
        [DataMember(Name = "email_verified")]
        public bool EmailVerified { get; set; }

        /// <summary>
        /// 格式化显示
        /// </summary>
        public override string ToString()
        {
            return $"{Name ?? Username} ({Email})";
        }
    }

    /// <summary>
    /// Realm 级别权限
    /// </summary>
    [DataContract]
    public class RealmAccess
    {
        [DataMember(Name = "roles")]
        public List<string> Roles { get; set; }
    }
}
