using System.ComponentModel;
using Hotline.Share.Enums.CallCenter;
using SqlSugar;
using XF.Domain.Entities;
using XF.Domain.Repository;

namespace Hotline.CallCenter.Tels
{
    [Description("分机休息记录")]
    public class TelRest : WorkflowEntity//, CreationModificationEntity
    {
        /// <summary>
        /// 分机id
        /// </summary>
        public string? TelId { get; set; }

        /// <summary>
        /// 分机号（冗余）
        /// </summary>
        public string TelNo { get; set; }

        /// <summary>
        /// 用户id
        /// </summary>
        public string UserId { get; set; }

        /// <summary>
        /// 用户名称（冗余）
        /// </summary>

        public string UserName { get; set; }

        /// <summary>
        /// 开始休息时间
        /// </summary>
        [SugarColumn(ColumnDescription = "开始休息时间")]
        public DateTime? StartTime { get; set; }

        /// <summary>
        /// 结束休息时间
        /// </summary>
        [SugarColumn(ColumnDescription = "结束休息时间")]
        public DateTime? EndTime { get; private set; }

        /// <summary>
        /// 休息时长（单位：秒）
        /// </summary>
        [SugarColumn(ColumnDescription = "休息时长（单位：秒）")]
        public double RestDuration { get; private set; }

        public string Reason { get; set; }
        /// <summary>
        /// 审核状态
        /// </summary>
        public ETelRestApplyStatus ApplyStatus { get; set; }

        /// <summary>
        /// 工号（冗余）
        /// </summary>
        [SugarColumn( IsNullable = true)]
        public string? StaffNo { get; set; }


        public TelRest()
        {

        }

        public TelRest(string telId, string telNo, string userId, string userName,string reason,bool isApply,string staffNo)
        {
            TelId = telId; TelNo = telNo; UserId = userId; UserName = userName; Reason = reason;StaffNo = staffNo;

            if(isApply)
            {
                ApplyStatus = ETelRestApplyStatus.NoAudit;
            }
            else
            {
                ApplyStatus = ETelRestApplyStatus.Resting;
                StartTime = DateTime.Now;
            }
        }


        


        public void EndRest()
        {
            EndTime = DateTime.Now;
            RestDuration = (EndTime.Value - StartTime.Value).TotalSeconds;
            ApplyStatus = ETelRestApplyStatus.Ending;
        }
    }
}
