using AI.Platform.Core;
using AI.Platform.Core.Entity.Media;
using Microsoft.AspNetCore.Components;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;

namespace AI.Platform.Page.Pages.Media.Model
{
    public class MediaModel
    {
    }

    /// <summary>
    /// 用于新增/修改广告时传递弹窗数据
    /// </summary>
    public class MediaDialogModel
    {
        /// <summary>
        /// 表id
        /// </summary>
        public long? Id { get; set; }

        /// <summary>
        /// 弹窗类型：1：新增；2：编辑；3：删除
        /// </summary>
        public int Type { get; set; }

        /// <summary>
        /// 集团ID
        /// </summary>
        public string GroupID { get; set; }

        /// <summary>
        /// 站点ID
        /// </summary>
        public string BusinessUnitID { get; set; }

        /// <summary>
        /// 文件名
        /// </summary>
        public string FileName { set; get; }

        /// <summary>
        /// 文件后缀
        /// </summary>
        public string FileExtension { set; get; }

        /// <summary>
        /// guid文件名
        /// </summary>
        public string GuidFileName { set; get; }

        /// <summary>
        /// 保存到服务器的地址
        /// </summary>
        public string SavePath { set; get; }

        /// <summary>
        /// 文件开始播放时间
        /// </summary>
        public int? StartTime { set; get; }

        /// <summary>
        /// 文件结束播放时间
        /// </summary>
        public int? EndTime { set; get; }

        /// <summary>
        /// 文件生效时间
        /// </summary>
        public DateTime? EffecitiveTime { set; get; }

        /// <summary>
        /// 文件失效时间
        /// </summary>
        public DateTime? FailureTime { set; get; }

        /// <summary>
        /// 文件油机状态
        /// </summary>
        public List<string> MachineStateList { set; get; }

        /// <summary>
        /// 文件广告状态 0:禁用；1：可用
        /// </summary>
        public int MediaState { set; get; }

        /// <summary>
        /// 文件上传人
        /// </summary>
        public string MediaUploader { set; get; } = Global.CurrentUser.NickName;

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


        public MediaEntity ToCompany()
        {
            var media = new MediaEntity()
            {
                LocalPath = SavePath,
                GroupID = this.GroupID ?? "",
                BusinessUnitID = this.BusinessUnitID ?? "",
                FileName = FileName,
                FileExtension = this.FileExtension,
                GuidFileName = this.GuidFileName,
                StartTime = this.StartTime ?? 0,
                EndTime = this.EndTime ?? 0,
                EffectiveTime = this.EffecitiveTime ?? DateTime.Now,
                FailureTime = this.FailureTime ?? DateTime.Now,
                MachineState = JsonSerializer.Serialize(getMachineStateList()),
                MediaState = this.MediaState,
                Uploader = this.MediaUploader ?? "",
                CreateTime = DateTime.Now,
                EditTime = DateTime.Now,
                Remark = this.Remark
            };
            if(this.Id != null) media.Id = (long)Id;
            return media;
        }

        /// <summary>
        /// 获取油机状态列表，为空则返回所有状态
        /// </summary>
        /// <returns></returns>
        public List<string> getMachineStateList()
        {
            if (MachineStateList.IsNullOrEmpty())
            {
                return new List<string>
                {
                    "idle","lock","offline","lift","authorised","start","fueling"
                };
            }

            return MachineStateList;
        }
    }
}
