using AI.Platform.Core;
using AI.Platform.Core.Entity.Device;
using AI.Platform.Core.Entity.Site;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;

namespace AI.Platform.Page.Pages.Site.Model
{
    internal class SiteModel
    {
    }

    /// <summary>
    /// 站点列表显示数据
    /// </summary>
    public class SiteOutput
    {
        /// <summary>
        /// id
        /// </summary>
        public virtual long Id { get; set; }

        /// <summary>
        /// 父站id
        /// </summary>
        public long ParentID { get; set; }

        /// <summary>
        /// 站名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 父级站名
        /// </summary>
        public string ParentName { get; set; }

        /// <summary>
        /// 油站地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 联系方式
        /// </summary>
        public string Contact { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public virtual DateTime? CreateTime { get; set; }
    }

    /// <summary>
    /// 站点编辑弹框传递数据
    /// </summary>
    public class StateDialogModel
    {
        /// <summary>
        /// 弹窗类型：1：新增；2：编辑；3：删除
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// id
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 站名
        /// </summary>
        [Required(ErrorMessage = "请填写站名")]
        public string Name { get; set; }

        /// <summary>
        /// 父级站点id
        /// </summary>
        public long ParentId { get; set; }

        /// <summary>
        /// 可供选择的父站
        /// </summary>
        public List<SiteInfo> Sites { get; set; }

        /// <summary>
        /// 油站地址
        /// </summary>
        [Required(ErrorMessage = "请填写油站地址")]
        public string Address { get; set; }

        /// <summary>
        /// 联系方式
        /// </summary>
        [Required(ErrorMessage = "请填写联系方式")]
        public string Contact { get; set; }

        /// <summary>
        /// 上传文件大小
        /// </summary>
        public long MaxSize { get; set; } = 31457280; //30M

        public SiteEntity ToCompany()
        {
            SiteEntity siteEntity = new SiteEntity()
            {
                ParentId = ParentId == 0 ? Global.CurrentUser.SiteId : ParentId,
                Name = Name,
                Address = Address,
                Contact = Contact,
                MaxSize = MaxSize,
                CreateTime = DateTime.Now
            };

            if (Id != null) siteEntity.Id = (long)this.Id;
            return siteEntity;
        }
    }

    /// <summary>
    /// 用于记录站点信息，提供给用户信息编辑弹窗输送站点信息
    /// </summary>
    public class SiteInfo
    {
        /// <summary>
        /// 站点id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 父站点id
        /// </summary>
        public long ParentId { get; set; }

        /// <summary>
        /// 站名
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 上传文件大小
        /// </summary>
        public long MaxSize { get; set; }
    }

    /// <summary>
    /// 用于显示设备列表
    /// </summary>
    public class SnInfo
    {
        /// <summary>
        /// Id
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        /// <summary>
        /// 站点id
        /// </summary>
        public long SiteId { get; set; }

        /// <summary>
        /// 站名
        /// </summary>
        public string siteName { get; set; }

        /// <summary>
        /// 设备SN
        /// </summary>
        public string sn { get; set; }

        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime EditTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }
    }

    /// <summary>
    /// 设备编辑弹框传递数据
    /// </summary>
    public class ScrrenDialogModel
    {
        /// <summary>
        /// 弹窗类型：1：新增；2：编辑；3：删除
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// Id
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 站点id
        /// </summary>
        [Required(ErrorMessage = "请绑定站点")]
        public long SiteId { get; set; }

        /// <summary>
        /// 站名
        /// </summary>
        public string siteName { get; set; }

        /// <summary>
        /// 设备SN
        /// </summary>
        [Required(ErrorMessage = "请输入设备码")]
        public string sn { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime createTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 可供选择的站点
        /// </summary>
        public List<SiteInfo> Sites { get; set; }

        public ScreentEntity ToCompany()
        {
            ScreentEntity screentEntity = new ScreentEntity()
            {
                sn = sn,
                SiteId = SiteId,
                CreateTime = createTime,
                EditTime = DateTime.Now,
                Remark = Remark
            };

            if(Id != null) screentEntity.Id = (long)Id;

            return screentEntity;
        }
    }
}
