/*
   Copyright (c) 2013, 2021, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
*/

/* TableMetadata object represents a table.
   This is the object returned in the getTable() callback.
   indexes[0] will *ALWAYS* represent the intrinsic primary key.
*/
TableMetadata = {
  database         : "", // Database name
  name             : "", // Table Name
  columns          : {}, // ordered array of ColumnMetadata objects
  indexes          : {}, // array of IndexMetadata objects 
  foreignKeys      : {}, // array of ForeignKeyMetadata objects
  partitionKey     : {}, // ordered array of column numbers in the partition key
};


/* ColumnMetadata object represents a column.
*/
ColumnMetadata = {
  /* Required Properties */
  name             : ""   , // column name
  columnNumber     : -1   , // position of column in table, and in columns array
  columnType       : ""   , // a ColumnType
  isIntegral       : false, // true if column is some variety of INTEGER type
  isNullable       : false, // true if NULLABLE
  isInPrimaryKey   : false, // true if column is part of PK
  isInPartitionKey : false, // true if column is part of partition key
  columnSpace      : 0    , // buffer space required for encoded stored value
  defaultValue     : null , // default value for column: null for default NULL; 
                            // undefined for no default; or a type-appropriate
                            // value for column
  
  /* Optional Properties, depending on columnType */
  /* Group A: Numeric */
  isUnsigned       : false,  //  true for UNSIGNED
  intSize          : null ,  //  1,2,3,4, or 8 if column type is INT
  scale            : 0    ,  //  DECIMAL scale
  precision        : 0    ,  //  DECIMAL precision
  isAutoincrement  : false,  //  true for AUTO_INCREMENT columns

  /* Group B: Non-numeric */
  length           : 0    ,  //  CHAR or VARCHAR length in characters
  isBinary         : false,  //  true for BLOB/BINARY/VARBINARY
  charsetName      : ""   ,  //  name of charset
};


/* IndexMetadata represents a table index.  

   The "indexes" array of TableMetadata will hold one or two IndexMetadata 
   records per table index.  For an index that is both unique and ordered, two
   records are created, one with the isUnique flag set, and the other with the 
   isOrdered flag set. 
*/
IndexMetadata = {
  name             : ""    ,  // Index name; undefined for PK 
  isPrimaryKey     : true  ,  // true for PK; otherwise undefined
  isUnique         : true  ,  // true or false
  isOrdered        : true  ,  // true or false; can scan if true
  columnNumbers    : null  ,  // an ordered array of column numbers
};


/* ForeignKeyMetadata represents a foreign key constraint.  

   The "foreignKeys" array of TableMetadata will hold the foreign key constraints.
    
*/
ForeignKeyMetadata = {
  name             : ""    ,  // Constraint name 
  columnNames      : null  ,  // an ordered array of column numbers
  targetTable      : ""    ,  // referenced table name
  targetDatabase   : ""    ,  // referenced database
  targetColumnNames: null  ,  // an ordered array of target column names
};


ColumnTypes =  [
  "TINYINT",
  "SMALLINT",
  "MEDIUMINT",
  "INT",
  "BIGINT",
  "FLOAT",
  "DOUBLE",
  "DECIMAL",
  "CHAR",
  "VARCHAR",
  "BLOB",
  "TEXT",
  "DATE",
  "TIME",
  "DATETIME",
  "YEAR",
  "TIMESTAMP",
  "BIT",
  "BINARY",
  "VARBINARY"
];


exports.ColumnTypes = ColumnTypes;
