using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using YBDevice.Entity;

namespace YBDevice.NApi.Application.ThirdClient
{
    /// <summary>
    /// 基础信息
    /// </summary>
    public class BaseInfo
    {
        /// <summary>
        /// 身高,单位厘米
        /// </summary>
        [Range(30, 300, ErrorMessage = "身高只能在30-300厘米之间")]
        public decimal Height { get; set; }
        /// <summary>
        /// 体重,kg
        /// </summary>
        [Range(1, 300, ErrorMessage = "体重只能在1-300公斤之间")]
        public decimal Weight { get; set; }
    }

    /// <summary>
    /// 计算BMI
    /// </summary>
    public class BmiInfoC2SDto: BaseInfo,IValidatableObject
    {
        /// <summary>
        /// 性别,1-男,2-女
        /// </summary>
        public GenderType Sex { get; set; }
        /// <summary>
        /// 出生年月
        /// </summary>
        public DateTime Birthday { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Birthday > DateTime.Now.Date)
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
            if (Birthday < DateTime.Now.Date.AddYears(-100))
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
        }
    }
    /// <summary>
    /// 身高预测
    /// </summary>
    public class HeightInfoC2SDto:IValidatableObject
    {
        /// <summary>
        /// 爸爸身高
        /// </summary>
        [Range(10, 300, ErrorMessage = "身高只能在30-300厘米之间")]
        public decimal DadHeight { get; set; }
        /// <summary>
        /// 妈妈身高
        /// </summary>
        [Range(10, 300, ErrorMessage = "身高只能在10-300厘米之间")]
        public decimal MomHeight { get; set; }
        /// <summary>
        /// 生日
        /// </summary>
        public DateTime Birthday { get; set; }
        /// <summary>
        /// 性别,1-男,2-女
        /// </summary>
        public GenderType sex { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Birthday > DateTime.Now.Date)
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
            if (Birthday < DateTime.Now.Date.AddYears(-100))
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
        }
    }
    /// <summary>
    /// code2session接口参数
    /// </summary>
    public class TouTiaoLoginC2SDto : LoginClientS2SDto
    {
        /// <summary>
        /// login 接口返回的登录凭证
        /// </summary>
        [Required(ErrorMessage ="code值不可为空")]
        public string code { get; set; }
        /// <summary>
        /// login 接口返回的匿名登录凭证
        /// </summary>
        public string anonymous_code { get; set; } = "";
    }
    /// <summary>
    /// 用户注册信息
    /// </summary>
    public class SubmitUserInfoC2SDto : LoginClientS2SDto
    {
        /// <summary>
        /// 唯一id,作为换取登录信息的凭据
        /// </summary>
        [Required(ErrorMessage = "sessionid不可为空")]
        public string sessionId { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string avatarUrl { get; set; }
        /// <summary>
        /// 昵称
        /// </summary>
        public string nickName { get; set; }
    }

    /// <summary>
    /// 小程序解密信息
    /// </summary>
    public class DecryptUserInfoC2SDto : LoginClientS2SDto
    {
        /// <summary>
        /// 唯一id,作为换取登录信息的凭据
        /// </summary>
        [Required(ErrorMessage ="sessionid不可为空")]
        public string sessionId { get; set; }
        /// <summary>
        /// 加密数据
        /// </summary>
        [Required(ErrorMessage = "数据不可为空")] 
        public string encryptedData { get; set; }
        /// <summary>
        /// 向量
        /// </summary>
        [Required(ErrorMessage = "向量不可为空")] 
        public string iv { get; set; }
    }

    /// <summary>
    /// 登录客户端类型
    /// </summary>
    public class LoginClientS2SDto
    {
        /// <summary>
        /// 客户端类型,1-微信小程序,2-字节小程序
        /// </summary>
        public int UA { get; set; }
    }
    /// <summary>
    /// 添加测量记录
    /// </summary>
    public class InsertResultC2SDto: BaseInfo
    {
        /// <summary>
        /// 记录时间
        /// </summary>
        public DateTime? CreateTime { get; set; }
        /// <summary>
        /// 家庭成员ID
        /// </summary>
        public Guid FamilyId { get; set; }
    }
    /// <summary>
    /// 测量记录信息
    /// </summary>
    public class ResultListS2CDto
    {
        /// <summary>
        /// 身高值,CM
        /// </summary>
        public decimal Height { get; set; }
        /// <summary>
        /// 体重,CM
        /// </summary>
        public decimal Weight { get; set; }

        /// <summary>
        /// BMI值
        /// </summary>
        public decimal BMI { get; set; }
        /// <summary>
        /// 记录时间
        /// </summary>
        public string CreateTime { get; set; }
    }
    /// <summary>
    /// 用户资料
    /// </summary>
    public class UserInfoS2CDto
    {
        /// <summary>
        /// 用户昵称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        public string HeadImg { get; set; }
        /// <summary>
        /// 身高值,CM
        /// </summary>
        public decimal Height { get; set; }
        /// <summary>
        /// 体重,CM
        /// </summary>
        public decimal Weight { get; set; }
        /// <summary>
        /// BMI值
        /// </summary>
        public decimal BMI { get; set; }
        /// <summary>
        /// 性别,1-男,2-女
        /// </summary>
        public GenderType Sex { get; set; }
        /// <summary>
        /// 出生年月
        /// </summary>
        public DateTime? Birthday { get; set; }
        /// <summary>
        /// 最近记录时间
        /// </summary>
        public DateTime? LastResultTime { get; set; }
        /// <summary>
        /// 年龄,小于16岁的显示几岁几个月,其他只显示整岁
        /// </summary>
        public string Age { get; set; }
        /// <summary>
        /// 家庭成员ID
        /// </summary>
        public Guid FamilyId { get; set; }

        /// <summary>
        /// BMI等级
        /// </summary>
        public string BMILevel { get; set; }
        /// <summary>
        /// 身高等级
        /// </summary>
        public string HeightLevel { get; set; }
        /// <summary>
        /// 体重等级
        /// </summary>
        public string WeightLevel { get; set; }
        /// <summary>
        /// BMI等级颜色
        /// </summary>
        public string BMILevelColor { get; set; }
        /// <summary>
        /// 身高等级颜色
        /// </summary>
        public string HeightLevelColor { get; set; }
        /// <summary>
        /// 体重等级颜色
        /// </summary>
        public string WeightLevelColor { get; set; }
        /// <summary>
        /// 头围等级颜色
        /// </summary>
        public string HeadLevelColor { get; set; }
        /// <summary>
        /// BMI分级列表
        /// </summary>
        public List<MeasureInfoItemValue> BMILevelList { get; set; }

        /// <summary>
        /// 身高分级列表
        /// </summary>
        public List<MeasureInfoItemValue> HeightLevelList { get; set; }

        /// <summary>
        /// 体重分级列表
        /// </summary>
        public List<MeasureInfoItemValue> WeightLevelList { get; set; }
    }
    /// <summary>
    /// 用户资料修改
    /// </summary>
    public class SumitUserInfoC2SDto : BaseInfo,IValidatableObject
    {
        /// <summary>
        /// 性别,1-男,2-女
        /// </summary>
        public int Sex { get; set; }
        /// <summary>
        /// 出生年月
        /// </summary>
        public DateTime Birthday { get; set; }
        /// <summary>
        /// 家庭成员ID
        /// </summary>
        public Guid FamilyId { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Sex != 1 && Sex != 2)
            {
                yield return new ValidationResult("请先选择性别", new[] { nameof(Sex) });
            }
            if (Birthday > DateTime.Now.Date)
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
            if (Birthday < DateTime.Now.Date.AddYears(-100))
            {
                yield return new ValidationResult("请选择正确的出生年月", new[] { nameof(Birthday) });
            }
        }
    }
}
