package com.aicheck.model;

/**
 * 字段级 diff 结果，用于通知中的 [新增]/[删除]/[修改] 行。
 */
public class FieldChange {
    /** 字段变更种类 */
    public enum ChangeKind {
        ADDED, REMOVED, MODIFIED
    }

    private final ChangeKind kind;
    private final String fieldName;
    private final String description;
    private final String oldType;
    private final String newType;
    private final String oldDescription;
    private final String detail;

    private FieldChange(ChangeKind kind, String fieldName, String description,
                        String oldType, String newType, String oldDescription, String detail) {
        this.kind = kind;
        this.fieldName = fieldName;
        this.description = description;
        this.oldType = oldType;
        this.newType = newType;
        this.oldDescription = oldDescription;
        this.detail = detail;
    }

    /** 构造新增字段变更 */
    public static FieldChange added(FieldInfo field) {
        return new FieldChange(ChangeKind.ADDED, field.getName(), field.getDescription(),
                null, field.getType(), null, null);
    }

    /** 构造删除字段变更 */
    public static FieldChange removed(FieldInfo field) {
        return new FieldChange(ChangeKind.REMOVED, field.getName(), field.getDescription(),
                field.getType(), null, field.getDescription(), null);
    }

    /** 构造修改字段变更，detail 通常为类型变化描述 */
    public static FieldChange modified(FieldInfo oldField, FieldInfo newField, String detail) {
        return new FieldChange(ChangeKind.MODIFIED, newField.getName(), newField.getDescription(),
                oldField.getType(), newField.getType(), oldField.getDescription(), detail);
    }

    public ChangeKind getKind() {
        return kind;
    }

    public String getFieldName() {
        return fieldName;
    }

    /** 变更后的字段说明（通知「说明」段） */
    public String getDescription() {
        return description;
    }

    public String getOldType() {
        return oldType;
    }

    public String getNewType() {
        return newType;
    }

    public String getOldDescription() {
        return oldDescription;
    }

    /** 结构性变更详情，如 Integer → String */
    public String getDetail() {
        return detail;
    }
}
