package com.dne.ems.dto;

import java.time.LocalDateTime;

import com.dne.ems.model.enums.OperationType;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 操作日志数据传输对象，用于前端展示用户操作记录。
 *
 * @version 1.0
 * @since 2025-06-20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class OperationLogDTO {
    /**
     * 操作日志ID
     */
    private Long id;
    
    /**
     * 用户ID
     */
    private Long userId;
    
    /**
     * 用户名称
     */
    private String userName;
    
    /**
     * 操作类型
     */
    private OperationType operationType;
    
    /**
     * 操作类型的中文描述
     */
    private String operationTypeDesc;
    
    /**
     * 操作描述
     */
    private String description;
    
    /**
     * 操作对象ID
     */
    private String targetId;
    
    /**
     * 操作对象类型
     */
    private String targetType;
    
    /**
     * 客户端IP地址
     */
    private String ipAddress;
    
    /**
     * 操作时间
     */
    private LocalDateTime createdAt;
    
    /**
     * 根据操作类型获取中文描述
     * 
     * @param operationType 操作类型
     * @return 中文描述
     */
    public static String getOperationTypeDesc(OperationType operationType) {
        if (operationType == null) {
            return "未知操作";
        }
        
        return switch (operationType) {
            case LOGIN -> "登录";
            case LOGOUT -> "登出";
            case CREATE -> "创建";
            case UPDATE -> "更新";
            case DELETE -> "删除";
            case ASSIGN_TASK -> "分配任务";
            case SUBMIT_TASK -> "提交任务";
            case APPROVE_TASK -> "审批任务";
            case REJECT_TASK -> "拒绝任务";
            case SUBMIT_FEEDBACK -> "提交反馈";
            case APPROVE_FEEDBACK -> "审批反馈";
            case REJECT_FEEDBACK -> "拒绝反馈";
            case OTHER -> "其他操作";
            default -> "未知操作";
        };
    }
} 