package org.springblade.sqlfly.config;

import java.io.Serializable;
import java.util.List;

import lombok.Data;

/**
 * 数据库表
 * 
 * @author William
 * @date 2022年10月28日 上午11:29:20
 */
@Data
public class Table implements Serializable {
	private static final long serialVersionUID = 1L;

    private String tableName;
    private String tableComment;
    private List<Column> columns;

    public Table() {
    }

    public Table(String tableName) {
        this.tableName = tableName;
    }

    public Table(String tableName, String tableComment) {
        this.tableName = tableName;
        this.tableComment = tableComment;
    }

    /**
     * 主键列
     *
     * @return
     */
    public Column getPrimaryColumn() {
        if (columns != null) {
            for (Column column : columns) {
                if (column.getPrimaryKey()) {
                    return column;
                }
            }
        }
        return null;
    }
}
