using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using Microsoft.EntityFrameworkCore;
using bitforum.Constants;

/// <summary>
/// 사용자단 일반 회원 정보
/// </summary>
namespace bitforum.Models.User
{
    [Table("Member")]
    [Comment("회원 정보")]
    [Index(nameof(SID), Name = "IX_Member_SID", IsUnique = true)]
    [Index(nameof(Email), Name = "IX_Member_Email", IsUnique = true)]
    [Index(nameof(Name), Name = "IX_Member_Name", IsUnique = true)]
    public class Member
    {
        [ForeignKey("ID")]
        public virtual MemberApprove MemberApproves { get; set; }

        [ForeignKey("GradeID")]
        public virtual MemberGrade MemberGrade { get; set; }

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Comment("PK")]
        public int ID { get; set; }

        [Comment("회원등급 ID")]
        public int? GradeID { get; set; } = null;

        [Required]
        [MaxLength(20)]
        [Comment("SID")]
        public string SID { get; set; } // 무작위 문자열

        [Required]
        [MaxLength(255)]
        [Comment("이메일")]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }

        [MaxLength(20)]
        [Comment("별명")]
        public string? Name { get; set; } = null;

        [MaxLength(40)]
        [Comment("본명")]
        public string? FullName { get; set; } = null;

        [MaxLength(20)]
        [Comment("본명(성)")]
        public string? FirstName { get; set; } = null;

        [MaxLength(40)]
        [Comment("본명(이름)")]
        public string? LastName { get; set; } = null;

        [Required]
        [MaxLength(255)]
        [Comment("비밀번호")]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [MaxLength(1000)]
        [Comment("자기소개")]
        public string? Intro { get; set; } = null;

        [MaxLength(50)]
        [Comment("한마디")]
        public string? Summary { get; set; } = null;

        [Comment("코인")]
        public long Coin { get; set; } = 0;

        [Comment("경험치")]
        public int Exp { get; set; } = 0;

        [MaxLength(15)]
        [Comment("연락처")]
        public string? Phone { get; set; } = null;

        [MaxLength(10)]
        [Comment("생년월일")]
        public DateOnly? Birthday { get; set; } = null;

        [MaxLength(6)]
        [Comment("성별")]
        public Gender? Gender { get; set; } = null;

        [MaxLength(255)]
        [Comment("사진")]
        public string? Photo { get; set; } = null;
   
        [Comment("이메일 인증 여부")]
        public bool IsEmailVerified { get; set; } = false;

        [Comment("본인 인증 여부")]
        public bool IsAuthCertified { get; set; } = false;

        [Comment("차단 여부")]
        public bool IsDenied { get; set; } = false;

        [Comment("운영진 여부")]
        public bool IsAdmin { get; set; } = false;

        [Comment("탈퇴 여부")]
        public bool IsWithdraw { get; set; } = false;

        [Comment("구독 중")]
        public int Following { get; set; } = 0;

        [Comment("구독자")]
        public int Followed { get; set; } = 0;

        [MaxLength(400)]
        [Comment("로그인 단말기 정보")]
        public string? DeviceInfo { get; set; } = null;

        [Required]
        [MaxLength(15)]
        [Comment("회원가입 시 IP")]
        public string SignupIP { get; set; }

        [MaxLength(15)]
        [Comment("마지막 로그인 IP")]
        public string? LastLoginIp { get; set; } = null;

        [Comment("마지막 로그인 일시")]
        public DateTime? LastLoginAt { get; set; } = null;

        [Comment("이메일 인증 일시")]
        public DateTime? EmailVerifiedAt { get; set; } = null;

        [Comment("본인인증 일시")]
        public DateTime? AuthCertifiedAt { get; set; } = null;

        [Required]
        [Comment("비밀번호 변경 일시")]
        public DateTime PasswordUpdatedAt { get; set; }

        [Required]
        [Comment("가입 일시")]
        public DateTime CreatedAt { get; set; }

        [Comment("수정 일시")]
        public DateTime? UpdatedAt { get; set; } = null;

        [Comment("탈퇴 일시")]
        public DateTime? DeletedAt { get; set; } = null;
    }
}
