using Hotline.Share.Dtos;
using Hotline.Share.Dtos.Settings;
using Hotline.Share.Enums.Order;
using Mapster;
using SqlSugar;
using System.ComponentModel;
using XF.Domain.Repository;

namespace Hotline.Settings;

/// <summary>
/// 短信回访规则设置
/// </summary>
[Description("短信回访规则设置")]
public class SettingOrderVisitSmsReplyRule : FullStateEntity
{
    /// <summary>
    /// 名字
    /// </summary>
    [SugarColumn(ColumnDescription = "规则名字")]
    public string Name { get; set; }

    /// <summary>
    /// 回访方式
    /// </summary>
    [SugarColumn(IsNullable = true, ColumnDescription = "回访方式(不需要更新就填NULL)")]
    public EVisitType? VisitType { get; set; }

    /// <summary>
    /// 回复内容匹配正则
    /// </summary>
    [SugarColumn(ColumnDescription = "回复内容匹配正则")]
    public string ReplyRegular { get; set; }

    /// <summary>
    /// 当前系统环境:ZiGong,YiBin,LuZhou
    /// </summary>
    [SugarColumn(ColumnDescription = "当前系统环境")]
    public string AppScope { get; set; }

    /// <summary>
    /// 唯一标识(ReplyRegular + AppScope 的 MD5)
    /// </summary>
    [SugarColumn(ColumnDescription = "唯一标识")]
    public string UniqueKey { get; set; }

    /// <summary>
    /// 回访状态(不需要更新就填NULL)
    /// </summary>
    [SugarColumn(ColumnDescription = "回访状态(不需要更新就填NULL)")]
    public EVisitState? VisitState { get; set; }

    /// <summary>
    /// 话务员评价（话务评价）
    /// </summary>
    [SugarColumn(ColumnDescription = "话务员评价(不需要更新就填NULL)")]
    public ESeatEvaluate? SeatEvaluate { get; set; }

    /// <summary>
    /// 语音评价（话务评价）
    /// </summary>
    [SugarColumn(ColumnDescription = "语音评价(不需要更新就填NULL)")]
    public EVoiceEvaluate? VoiceEvaluate { get; set; }

    /// <summary>
    /// 短信语音评价(话务评价)
    /// </summary>
    [SugarColumn(ColumnDescription = "短信语音评价(不需要更新就填NULL)")]
    public EVoiceEvaluate? SmSVoiceEvaluate { get; set; }

    /// <summary>
    /// 部门办件态度
    /// </summary>
    [SugarColumn(ColumnDescription = "部门办件态度(不需要更新就填NULL)")]
    public int? OrgHandledAttitude { get; set; }

    /// <summary>
    /// 部门办件结果
    /// </summary>
    [SugarColumn(ColumnDescription = "部门办件结果(不需要更新就填NULL)")]
    public int? OrgProcessingResults { get; set; }

    /// <summary>
    /// 回访内容
    /// </summary>
    [SugarColumn(ColumnDescription = "回访内容(不需要更新就填NULL)")]
    public string? VisitContent { get; set; }

    /// <summary>
    /// 是否回填用户短信内容到部门回访内容
    /// </summary>
    [SugarColumn(ColumnDescription = "是否回填用户短信内容到部门回访内容")]
    public bool? IsReplyToOrgVisitContent { get; set; }

    /// <summary>
    /// 匹配的顺序,从小到大
    /// </summary>

    [SugarColumn(ColumnDescription = "匹配的顺序,从小到大")]
    public int SortOrder { get; set; }

    public Kv? GetOrgHandledAttitude(IReadOnlyCollection<SystemDicDataOutDto> visitSatisfaction)
    {
        if (this.OrgHandledAttitude == null) return null;
        return visitSatisfaction.First(m => m.DicDataValue == OrgHandledAttitude.ToString()).Adapt<Kv>();
    }

    public Kv? GetOrgProcessingResults(IReadOnlyCollection<SystemDicDataOutDto> visitSatisfaction)
    {
        if (OrgProcessingResults == null) return null;
        return visitSatisfaction.First(m => m.DicDataValue == OrgProcessingResults.ToString()).Adapt<Kv>();
    }
}
