package cn.novalon.gym.manage.sys.audit.domain;

import cn.novalon.gym.manage.sys.core.domain.BaseDomain;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;

/**
 * 审计日志领域对象
 * 
 * @author 张翔
 * @date 2026-04-01
 */
@Schema(description = "审计日志实体")
public class AuditLog extends BaseDomain {

    @Schema(description = "实体类型（如User, Role等）", example = "User")
    private String entityType;

    @Schema(description = "实体ID", example = "1")
    private Long entityId;

    @Schema(description = "操作类型（CREATE, UPDATE, DELETE）", example = "UPDATE")
    private String operationType;

    @Schema(description = "操作人", example = "admin")
    private String operator;

    @Schema(description = "操作时间")
    private LocalDateTime operationTime;

    @Schema(description = "变更前数据（JSON格式）")
    private String beforeData;

    @Schema(description = "变更后数据（JSON格式）")
    private String afterData;

    @Schema(description = "变更字段列表")
    private String[] changedFields;

    @Schema(description = "IP地址", example = "192.168.1.100")
    private String ipAddress;

    @Schema(description = "用户代理")
    private String userAgent;

    @Schema(description = "操作描述", example = "更新用户信息")
    private String description;

    public AuditLog() {
        this.operationTime = LocalDateTime.now();
    }

    public String getEntityType() {
        return entityType;
    }

    public void setEntityType(String entityType) {
        this.entityType = entityType;
    }

    public Long getEntityId() {
        return entityId;
    }

    public void setEntityId(Long entityId) {
        this.entityId = entityId;
    }

    public String getOperationType() {
        return operationType;
    }

    public void setOperationType(String operationType) {
        this.operationType = operationType;
    }

    public String getOperator() {
        return operator;
    }

    public void setOperator(String operator) {
        this.operator = operator;
    }

    public LocalDateTime getOperationTime() {
        return operationTime;
    }

    public void setOperationTime(LocalDateTime operationTime) {
        this.operationTime = operationTime;
    }

    public String getBeforeData() {
        return beforeData;
    }

    public void setBeforeData(String beforeData) {
        this.beforeData = beforeData;
    }

    public String getAfterData() {
        return afterData;
    }

    public void setAfterData(String afterData) {
        this.afterData = afterData;
    }

    public String[] getChangedFields() {
        return changedFields;
    }

    public void setChangedFields(String[] changedFields) {
        this.changedFields = changedFields;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String toString() {
        return "AuditLog{" +
                "id=" + id +
                ", entityType='" + entityType + '\'' +
                ", entityId=" + entityId +
                ", operationType='" + operationType + '\'' +
                ", operator='" + operator + '\'' +
                ", operationTime=" + operationTime +
                ", beforeData='" + beforeData + '\'' +
                ", afterData='" + afterData + '\'' +
                ", changedFields=" + java.util.Arrays.toString(changedFields) +
                ", ipAddress='" + ipAddress + '\'' +
                ", userAgent='" + userAgent + '\'' +
                ", description='" + description + '\'' +
                ", createBy='" + createBy + '\'' +
                ", updateBy='" + updateBy + '\'' +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                ", deletedAt=" + deletedAt +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        AuditLog auditLog = (AuditLog) o;
        return java.util.Objects.equals(entityType, auditLog.entityType) &&
               java.util.Objects.equals(entityId, auditLog.entityId) &&
               java.util.Objects.equals(operationType, auditLog.operationType) &&
               java.util.Objects.equals(operator, auditLog.operator) &&
               java.util.Objects.equals(operationTime, auditLog.operationTime) &&
               java.util.Objects.equals(beforeData, auditLog.beforeData) &&
               java.util.Objects.equals(afterData, auditLog.afterData) &&
               java.util.Arrays.equals(changedFields, auditLog.changedFields) &&
               java.util.Objects.equals(ipAddress, auditLog.ipAddress) &&
               java.util.Objects.equals(userAgent, auditLog.userAgent) &&
               java.util.Objects.equals(description, auditLog.description);
    }

    @Override
    public int hashCode() {
        return java.util.Objects.hash(super.hashCode(), entityType, entityId, operationType, operator, 
                                     operationTime, beforeData, afterData, java.util.Arrays.hashCode(changedFields), 
                                     ipAddress, userAgent, description);
    }
}
