using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YBDevice.Entity
{
    /// <summary>
    /// 科普资讯提交
    /// </summary>
    public class SecInfoSubmitModel
    {
        /// <summary>
        /// 内容
        /// </summary>
        [Required(ErrorMessage = "内容不可为空")]
        public string content { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 类型,1-文本,2-链接,3-跳转小程序
        /// </summary>
        public AdType Type { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        [MaxLength(50, ErrorMessage = "标题长度最多为50个字")]
        public string Title { get; set; }

        /// <summary>
        /// 所属分组ID
        /// </summary>
        public int TagId { get; set; }

        /// <summary>
        /// 封面图片地址
        /// </summary>
        [Required(ErrorMessage = "请先上传封面图片")]
        public string HeadImg { get; set; }

        /// <summary>
        /// 点击次数
        /// </summary>
        public int ClickCount { get; set; }

        /// <summary>
        /// 小程序appid
        /// </summary>
        [Required(ErrorMessage = "请先选择小程序")]
        public string AppId { get; set; }
    }
    /// <summary>
    /// 分组类型
    /// </summary>
    public class SecInfoTypeModel : YB_SecInfoType
    {
        /// <summary>
        /// 客户名称
        /// </summary>
        public string BusinessName { get; set; }
    }

    /// <summary>
    /// 科普资讯列表
    /// </summary>
    public class SecInfoListModel
    {
        /// <summary>
        /// 分组名
        /// </summary>
        public string tagname { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 类型,1-文本,2-链接,3-跳转小程序
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 所属分组ID
        /// </summary>
        public int TagId { get; set; }

        /// <summary>
        /// 封面图片地址
        /// </summary>
        public string HeadImg { get; set; }

        /// <summary>
        /// 点击次数
        /// </summary>
        public int ClickCount { get; set; }

        /// <summary>
        /// 状态,0-未开启,1-正常运行,2-已关闭
        /// </summary>
        public AdStatus Status { get; set; }

        /// <summary>
        /// 商户ID
        /// </summary>
        public int BusienssId { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }
    }
    /// <summary>
    /// 科普资讯列表
    /// </summary>
    public class SecInfoApiListModel
    {
        /// <summary>
        /// 记录ID
        /// </summary>
        public Guid Id { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 封面图
        /// </summary>
        public string HeadImg { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        public DateTime time { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        public string CreateTime { get; set; }
        /// <summary>
        /// 点击数
        /// </summary>
        public int ClickCount { get; set; }
        /// <summary>
        /// 内容,只有为链接、小程序时有效
        /// </summary>
        public string Content { get; set; } = "";
        /// <summary>
        /// 类型,1-文本,2-链接,3-小程序
        /// </summary>
        public AdType Type { get; set; }
    }

    /// <summary>
    /// 轮播图、开屏广告列表
    /// </summary>
    public class BannerListModel : YB_Banner
    {
        /// <summary>
        /// 客户名称
        /// </summary>
        public string BusinessName { get; set; }
    }
    /// <summary>
    /// 轮播图列表
    /// </summary>
    public class BannerApiListModel
    {
        /// <summary>
        /// 记录ID
        /// </summary>
        public int Id { get; set; }
        /// <summary>
        /// 封面图
        /// </summary>
        public string HeadImg { get; set; }
        /// <summary>
        /// 类型，1-文本,2-链接,3-跳转小程序
        /// </summary>
        public AdType Type { get; set; }
        /// <summary>
        /// 内容,只有小程序,链接有效
        /// </summary>
        public string content { get; set; }
    }
    /// <summary>
    /// 获取用户的轮播图列表
    /// </summary>
    public class BannerListC2SDto
    {
        /// <summary>
        /// 家庭成员ID
        /// </summary>
        public int FamilyId { get; set; }
        /// <summary>
        /// 小程序appid
        /// </summary>
        public string AppId { get; set; }
    }


    /// <summary>
    /// 轮播图、开屏广告信息提交
    /// </summary>
    public class BannerSubmitModel : IValidatableObject
    {
        /// <summary>
        /// 
        /// </summary>
        public System.Int32 Id { get; set; }

        /// <summary>
        /// 封面图
        /// </summary>
        [Required(ErrorMessage = "封面图不可为空")]
        public System.String HeadImg { get; set; }

        /// <summary>
        /// 轮播图名称
        /// </summary>
        [Required(ErrorMessage = "名称不可为空"), MaxLength(100, ErrorMessage = "名称最多100个字")]
        public System.String Name { get; set; }

        /// <summary>
        /// 类型,1-文本,2-链接,3-跳转小程序
        /// </summary>
        public AdType Type { get; set; }

        /// <summary>
        /// 小程序appid
        /// </summary>
        public string AppId { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string content { get; set; }
        /// <summary>
        /// 绑定的设备ID列表
        /// </summary>
        public List<int> equids { get; set; }

        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Type == AdType.URL && !content.ToLower().StartsWith("http"))
            {
                yield return new ValidationResult("链接格式不正确", new[] { nameof(content) });
            }
            if (Type == AdType.Text && string.IsNullOrEmpty(content))
            {
                yield return new ValidationResult("文本内容不可为空", new[] { nameof(content) });
            }
            if (Type == AdType.MINIAPP && string.IsNullOrEmpty(content))
            {
                yield return new ValidationResult("小程序appid不可为空", new[] { nameof(content) });
            }
            if (Type == AdType.MINIAPP && !content.ToLower().StartsWith("wx"))
            {
                yield return new ValidationResult("小程序appid格式不正确", new[] { nameof(content) });
            }
        }
    }
    /// <summary>
    /// 轮播图详情
    /// </summary>
    public class BannerDetaimS2CDto
    {
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        public string CreateTime { get; set; }
    }

    /// <summary>
    /// 广告内容详情
    /// </summary>
    public class AdDetailModel
    {
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }
        /// <summary>
        /// 发布时间
        /// </summary>
        public string CreateTime { get; set; }
    }
}
