package com.cool.modules.dingtalk.entity;

import com.cool.core.base.BaseEntity;
import com.mybatisflex.annotation.Table;
import com.cool.core.annotation.ColumnDefine;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * 钉钉同步日志实体
 * 用于记录每次同步的详细信息和结果
 */
@Getter
@Setter
@Table(value = "dingtalk_sync_log", comment = "钉钉同步日志表")
public class DingtalkSyncLogEntity extends BaseEntity<DingtalkSyncLogEntity> {

    @ColumnDefine(comment = "同步类型 0-手动 1-自动", notNull = true)
    private Integer syncType;

    @ColumnDefine(comment = "同步状态 0-失败 1-成功 2-部分成功", notNull = true)
    private Integer syncStatus;

    @ColumnDefine(comment = "部门同步成功数量", defaultValue = "0")
    private Integer deptSuccessCount;

    @ColumnDefine(comment = "部门同步失败数量", defaultValue = "0")
    private Integer deptFailCount;

    @ColumnDefine(comment = "用户同步成功数量", defaultValue = "0")
    private Integer userSuccessCount;

    @ColumnDefine(comment = "用户同步失败数量", defaultValue = "0")
    private Integer userFailCount;

    @ColumnDefine(comment = "错误信息", type = "TEXT")
    private String errorMsg;

    @ColumnDefine(comment = "耗时（毫秒）", defaultValue = "0")
    private Integer costTime;

    /**
     * 获取同步类型文本（用于前端显示）
     */
    @JsonProperty("syncTypeText")
    public String getSyncTypeText() {
        return syncType != null && syncType == 0 ? "手动" : "自动";
    }

    /**
     * 获取同步状态文本（用于前端显示）
     */
    @JsonProperty("syncStatusText")
    public String getSyncStatusText() {
        if (syncStatus == null) {
            return "未知";
        }
        if (syncStatus == 1) {
            return "成功";
        } else if (syncStatus == 2) {
            return "部分成功";
        } else {
            return "失败";
        }
    }
}
