package com.tmerclub.cloud.search.canal.model;

import lombok.Data;
import lombok.ToString;

import java.io.Serial;
import java.util.Objects;

/**
 * @author throwable
 * @version v1
 * @description
 * @since 2020/9/20 12:29
 */
@Data
@ToString
public class DefaultModelTable implements ModelTable {
    @Serial
    private static final long serialVersionUID = 1L;
    private final String database;
    private final String table;

    private DefaultModelTable(String database, String table) {
        this.database = database;
        this.table = table;
    }

    public static DefaultModelTable of(String database, String table) {
        return new DefaultModelTable(database, table);
    }

    @Override
    public String database() {
        return database;
    }

    @Override
    public String table() {
        return table;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        DefaultModelTable that = (DefaultModelTable) o;
        return Objects.equals(database, that.database) &&
                Objects.equals(table, that.table);
    }

    @Override
    public int hashCode() {
        return Objects.hash(database, table);
    }

    @Override
    public String toString() {
        return database() + "." + table();
    }
}
