using IRaCIS.Core.Domain.Share;
using Newtonsoft.Json;


namespace IRaCIS.Application.Contracts
{

    public class UserTypeViewModel
    {
        public Guid Id { get; set; }

        public string UserType { get; set; } = string.Empty;
        public UserTypeEnum UserTypeEnum { get; set; }
        public string Description { get; set; } = string.Empty;
    }

    public class UserLoginDTO
    {
        public string UserName { get; set; } = string.Empty;
        public string Password { get; set; } = string.Empty;

        public Guid? UserId { get; set; }
    }

    public class LoginReturnDTO
    {
        public UserBasicInfo BasicInfo { get; set; } = new UserBasicInfo();
        public string JWTStr { get; set; } = string.Empty;

        public bool IsMFA { get; set; } = false;

        public SystemEmailSendConfigView CompanyInfo { get; set; }

    }

    public class UserBasicInfo
    {
        public Guid Id { get; set; }
        public string UserName { get; set; } = string.Empty;
        public string RealName { get; set; } = string.Empty;
        public int? Sex { get; set; } // 1-男  2-女


        /// <summary>
        /// LastLoginIP
        /// </summary>
        public string LastLoginIP { get; set; } = string.Empty;

        public UserTypeEnum UserTypeEnum { get; set; }

        /// <summary>
        /// 上一次修改密码的时间
        /// </summary>
        public DateTime? LastChangePassWordTime { get; set; }
        public bool IsTestUser { get; set; }
        public bool IsAdmin { get; set; } = false;
        public string UserTypeShortName { get; set; } = string.Empty;
        public bool PasswordChanged { get; set; }
        public int Status { get; set; }
        public Guid UserTypeId { get; set; }

        public string Code { get; set; } = String.Empty;

        public string PermissionStr { get; set; } = String.Empty;

        public string EMail { get; set; } = string.Empty;
        public bool IsFirstAdd { get; set; }
        public bool IsReviewer { get; set; } = false;

        public int LoginState { get; set; } = 0;

    }

    public class MenuFuncTreeNodeView
    {
        [JsonIgnore]
        public Guid Id { get; set; }
        [JsonIgnore]
        public Guid ParentId { get; set; } = Guid.Empty;
        [JsonIgnore]
        public int ShowOrder { get; set; }

        public string routeName { get; set; } = string.Empty;
        public string component { get; set; } = string.Empty;
        public string redirect { get; set; } = string.Empty;
        public string path { get; set; } = string.Empty;
        public Meta meta { get; set; } = new Meta();
        public bool hidden { get; set; }
        public List<MenuFuncTreeNodeView> Childrens { get; set; } = new List<MenuFuncTreeNodeView>();
    }

    public class Meta
    {
        public string MetaTitle { get; set; } = string.Empty;
        public bool MetaBreadcrumb { get; set; } = false;
        public string MetaIcon { get; set; } = string.Empty;
        public string MetaActiveMenu { get; set; } = string.Empty;
    }


    public class FunctionTreeNodeDTO
    {
        [JsonIgnore]
        public Guid Id { get; set; }
        [JsonIgnore]
        public Guid ParentId { get; set; } = Guid.Empty;
        [JsonIgnore]
        public int ShowOrder { get; set; }

        public string RouteName { get; set; } = string.Empty;
        public string FunctionName { get; set; } = string.Empty;

        public List<FunctionTreeNodeDTO> Childrens { get; set; } = new List<FunctionTreeNodeDTO>();
    }



    public class UserDetailDTO : UserInfo
    {
        public bool CanEditUserType { get; set; }
    }

    public class UserInfo
    {
        public Guid Id { get; set; }
        public string UserName { get; set; } = string.Empty;
        public string Password { get; set; } = string.Empty;
        public string RealName { get; set; } = string.Empty;


        public string FirstName { get; set; } = string.Empty;

        public string LastName { get; set; } = string.Empty;
        public int? Sex { get; set; } // 1-男  2-女

        public int Status { get; set; } = 1; // 0-已删除 1-正常

        public string Phone { get; set; } = string.Empty;
        public string EMail { get; set; } = string.Empty;
        public Guid UserTypeId { get; set; } = Guid.Empty;

        public string UserCode { get; set; } = string.Empty;

        public bool IsZhiZhun { get; set; }

        public string UserType { get; set; } = string.Empty;

        public string UserTypeShortName { get; set; } = string.Empty;


        public UserTypeEnum UserTypeEnum { get; set; }



        //public Guid OrganizationTypeId { get; set; } = Guid.Empty;
        //public string OrganizationType { get; set; } = String.Empty;
        //public Guid OrganizationId { get; set; }
        public string OrganizationName { get; set; } = string.Empty;



        public string DepartmentName { get; set; } = String.Empty;
        public string PositionName { get; set; } = String.Empty;

        public bool IsTestUser { get; set; }
    }

    /// <summary>
    /// 添加用户是的返回模型
    /// </summary>
    public class UserAddedReturnDTO
    {
        public Guid Id { get; set; }
        public string UserCode { get; set; } = string.Empty;
    }


    public class UserCommand : UserInfo
    {
        public string BaseUrl { get; set; } = string.Empty;
        public string RouteUrl { get; set; } = string.Empty;

        //public string FirstName { get; set; }
        //public string LastName { get; set; }
    }

    public class EditPasswordCommand
    {
        public string NewUserName { get; set; } = string.Empty;

        public string NewPassWord { get; set; } = string.Empty;
        public string OldPassWord { get; set; } = string.Empty;
    }



    public class UserAccountDto
    {
        public Guid UserId { get; set; }

        public string UserName { get; set; } = string.Empty;

        public string UserRealName { get; set; } = string.Empty;

        public string UserType { get; set; } = string.Empty;
    }

    public class UserListQueryDTO : PageInput
    {
        public string UserName { get; set; } = string.Empty;
        public string RealName { get; set; }
        public string Phone { get; set; } = string.Empty;
        public string OrganizationName { get; set; } = string.Empty;
        public Guid? UserType { get; set; }

        public bool? IsTestUser { get; set; }

        public bool? IsZhiZhun { get; set; }
        public UserStateEnum? UserState { get; set; }

        public DateTime? BeginCreateTime { get; set; }

        public DateTime? EndCreateTime { get; set; }

        public string? EMail { get; set; }
    }

    public class UserRoleInfoDTO
    {
        public List<string> RoleList { get; set; } = new List<string>();
        public int MaxPrivilegeLevel { get; set; }
    }

    public class UserListDTO : UserInfo
    {
        [JsonIgnore]
        public Guid testGuid { get; set; }
        public bool CanEditUserType { get; set; }

        public DateTime CreateTime { get; set; }

        public List<string> RoleNameArray { get; set; } = new List<string>();
        public IEnumerable<RoleDTO> RoleNameList { get; set; } = new List<RoleDTO>();
    }


    public class UserIdRoleName : RoleDTO
    {
        public Guid UserId { get; set; }
    }
    public class UserIdRoleNameList
    {
        public Guid UserId { get; set; }
        public IEnumerable<RoleDTO> RoleList { get; set; } = new List<RoleDTO>();
    }


    public class AllowAnonymousResetPasswordCommand
    {
        public string Email { get; set; } = string.Empty;

        public string VerificationCode { get; set; } = string.Empty;

        public string NewPwd { get; set; } = string.Empty;

        public string UserName { get; set; } = string.Empty;
    }

    public class ResetPasswordCommand
    {
        public string EmailOrPhone { get; set; } = string.Empty;
        public VerifyType VerificationType { get; set; }
        public string VerificationCode { get; set; } = string.Empty;
        public string NewPwd { get; set; } = string.Empty;

        public bool IsReviewer { get; set; } = false;
    }
}