package ru.nbch.indicsearchservice.model;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@JsonPropertyOrder({"tableName", "fieldData", "relatedTableData"})
public class TableData {
    private String tableName;
    private List<FieldData> fieldData = new ArrayList<>();
    private List<TableData> relatedTableData = new ArrayList<>();

    public TableData() {
    }

    public TableData(String tableName, List<FieldData> fieldData) {
        this.tableName = tableName;
        this.fieldData = fieldData;
    }

    public TableData(String tableName, List<FieldData> fieldData, List<TableData> relatedTableData) {
        this.tableName = tableName;
        this.fieldData = fieldData;
        this.relatedTableData = relatedTableData;
    }

    public String getTableName() {
        return tableName;
    }

    public List<FieldData> getFieldData() {
        return fieldData;
    }

    public List<TableData> getRelatedTableData() {
        return relatedTableData;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        TableData tableData = (TableData) o;
        return Objects.equals(tableName, tableData.tableName) && Objects.equals(fieldData, tableData.fieldData) && Objects.equals(relatedTableData, tableData.relatedTableData);
    }

    @Override
    public int hashCode() {
        return Objects.hash(tableName, fieldData, relatedTableData);
    }

    @Override
    public String toString() {
        return "TableData{" +
            "tableName='" + tableName + '\'' +
            ", fieldData=" + fieldData +
            ", relatedTableData=" + relatedTableData +
            '}';
    }

    public record FieldData(String columnName,
                            Object columnValue) {
    }
}
