import type { DbType } from './components/dbTypes'

// Sentinel written into a job's `logs` field when it was fetched with
// `no_logs=true` (e.g. nested flow-status viewers during "Test flow").
// It is NOT empty logs — it means logs were intentionally skipped and can
// be lazily fetched. The log panel detects this and resolves the real logs.
export const WM_LOGS_SKIPPED = '__WM_LOGS_SKIPPED__'

export const DEFAULT_WEBHOOK_TYPE: 'async' | 'sync' = 'async'

export const HOME_SHOW_HUB = true

export const HOME_SHOW_CREATE_FLOW = true
export const HOME_SEARCH_SHOW_FLOW = true

export const HOME_SHOW_CREATE_APP = true

export const HOME_SEARCH_PLACEHOLDER = 'Search Scripts, Flows & Apps'

export const SIDEBAR_SHOW_SCHEDULES = true

export const WORKSPACE_SHOW_SLACK_CMD = true
export const WORKSPACE_SHOW_WEBHOOK_CLI_SYNC = true

export const SCRIPT_VIEW_SHOW_PUBLISH_TO_HUB = true

export const SCRIPT_VIEW_SHOW_SCHEDULE = true
export const SCRIPT_VIEW_SHOW_EXAMPLE_CURL = true

export const SCRIPT_VIEW_SHOW_CREATE_TOKEN_BUTTON = true

export const SCRIPT_VIEW_SHOW_RUN_FROM_CLI = true

export const SCRIPT_VIEW_SHOW_SCHEDULE_RUN_LATER = true

export const SCRIPT_VIEW_WEBHOOK_INFO_TIP = `Pass the input as a json payload, the token as a Bearer token (header: 'Authorization:
Bearer XXXX') or as query arg \`?token=XXX\`, and pass as header: 'Content-Type:
application/json'`

export const SCRIPT_VIEW_WEBHOOK_INFO_LINK = 'https://www.windmill.dev/docs/core_concepts/webhooks'

export const SCRIPT_EDITOR_SHOW_EXPLORE_OTHER_SCRIPTS = true

export const SCRIPT_CUSTOMISE_SHOW_KIND = true

export const WORKER_S3_BUCKET_SYNC_SETTING = 'worker_s3_bucket_sync'
export const CUSTOM_TAGS_SETTING = 'custom_tags'
export const DEFAULT_TAGS_PER_WORKSPACE_SETTING = 'default_tags_per_workspace'
export const DEFAULT_TAGS_WORKSPACES_SETTING = 'default_tags_workspaces'
export const FORK_WORKSPACE_TAG_APPEND_FORK_SUFFIX_SETTING = 'fork_workspace_tag_append_fork_suffix'
export const PREVIEW_TAGS_OVERRIDE_SETTING = 'preview_tags_override'

export const WORKSPACE_FAIRNESS_ENABLED_SETTING = 'workspace_fairness_enabled'
export const WORKSPACE_FAIRNESS_MAX_PERCENT_SETTING = 'workspace_fairness_max_percent'
export const WORKSPACE_FAIRNESS_DURATION_SECS_SETTING = 'workspace_fairness_duration_secs'
export const WORKSPACE_FAIRNESS_MIN_TOTAL_SETTING = 'workspace_fairness_min_total_jobs'

export const WORKSPACE_SLACK_BOT_TOKEN_PATH = 'f/slack_bot/bot_token'

export const POSTGRES_TYPES = [
	'VARCHAR',
	'VARCHAR[]',
	'TEXT',
	'TEXT[]',
	'INT',
	'INT[]',
	'BIGINT',
	'BIGINT[]',
	'BOOL',
	'BOOL[]',
	'CHAR',
	'CHAR[]',
	'SMALLINT',
	'SMALLINT[]',
	'SMALLSERIAL',
	'SMALLSERIAL[]',
	'SERIAL',
	'SERIAL[]',
	'BIGSERIAL',
	'BIGSERIAL[]',
	'REAL',
	'REAL[]',
	'FLOAT8',
	'FLOAT8[]',
	'NUMERIC',
	'NUMERIC[]',
	'DECIMAL',
	'DECIMAL[]',
	'OID',
	'OID[]',
	'DATE',
	'DATE[]',
	'TIME',
	'TIME[]',
	'TIMETZ',
	'TIMETZ[]',
	'TIMESTAMP',
	'TIMESTAMP[]',
	'TIMESTAMPTZ',
	'TIMESTAMPTZ[]',
	'JSON',
	'JSON[]',
	'JSONB',
	'JSONB[]',
	'BYTEA',
	'BYTEA[]'
]

export const MYSQL_TYPES = [
	'varchar',
	'char',
	'bin',
	'varbinary',
	'blob',
	'text',
	'enum',
	'set',
	'int',
	'tinyint',
	'smallint',
	'mediumint',
	'bigint',
	'integer',
	'bool',
	'bit',
	'float',
	'real',
	'dec',
	'fixed',
	'date',
	'datetime',
	'timestamp',
	'time'
]
export const ORACLEDB_TYPES = [
	'varchar2',
	'char',
	'nchar',
	'nvarchar2',
	'clob',
	'nclob',
	'blob',
	'number',
	'float',
	'binary_float',
	'binary_double',
	'date',
	'timestamp',
	'long',
	'rowid',
	'urowid'
]
export const BIGQUERY_TYPES = [
	'string',
	'string[]',
	'bytes',
	'bytes[]',
	'json',
	'json[]',
	'timestamp',
	'timestamp[]',
	'date',
	'date[]',
	'time',
	'time[]',
	'datetime',
	'datetime[]',
	'integer',
	'integer[]',
	'int64',
	'int64[]',
	'float64',
	'float64[]',
	'numeric',
	'numeric[]',
	'bignumeric',
	'bignumeric[]',
	'bool',
	'bool[]'
]

export const SNOWFLAKE_TYPES = [
	'varchar',
	'binary',
	'date',
	'time',
	'timestamp',
	'int',
	'float',
	'boolean'
]

export const MSSQL_TYPES = [
	'char',
	'varchar',
	'text',
	'nchar',
	'nvarchar',
	'ntext',
	'binary',
	'varbinary',
	'image',
	'date',
	'datetime2',
	'datetime',
	'datetimeoffset',
	'smalldatetime',
	'time',
	'bigint',
	'int',
	'tinyint',
	'smallint',
	'float',
	'real',
	'numeric',
	'decimal',
	'bit'
]
export const DUCKDB_TYPES = [
	'BIGINT',
	'INT8',
	'LONG',
	'BIT',
	'BITSTRING',
	'BLOB',
	'BYTEA',
	'BINARY',
	'VARBINARY',
	'BOOLEAN',
	'BOOL',
	'LOGICAL',
	'DATE',
	'DECIMAL',
	'NUMERIC',
	'DOUBLE',
	'FLOAT8',
	'FLOAT',
	'FLOAT4',
	'REAL',
	'HUGEINT',
	'INTEGER',
	'INT4',
	'INT',
	'SIGNED',
	'INTERVAL',
	'JSON',
	'SMALLINT',
	'INT2',
	'SHORT',
	'TIME',
	'TIMESTAMP WITH TIME ZONE',
	'TIMESTAMPTZ',
	'TIMESTAMP',
	'DATETIME',
	'TINYINT',
	'INT1',
	'UBIGINT',
	'UHUGEINT',
	'UINTEGER',
	'USMALLINT',
	'UTINYINT',
	'UUID',
	'VARCHAR',
	'CHAR',
	'BPCHAR',
	'TEXT',
	'STRING'
]

/** Types that are only valid for new columns (CREATE TABLE / ADD COLUMN), not for altering existing ones. */
export const NEW_COLUMN_ONLY_TYPES: string[] = [
	'SMALLSERIAL',
	'SMALLSERIAL[]',
	'SERIAL',
	'SERIAL[]',
	'BIGSERIAL',
	'BIGSERIAL[]'
]

export const DB_TYPES: Record<DbType, string[]> = {
	bigquery: BIGQUERY_TYPES,
	ms_sql_server: MSSQL_TYPES,
	mysql: MYSQL_TYPES,
	postgresql: POSTGRES_TYPES,
	snowflake: SNOWFLAKE_TYPES,
	duckdb: DUCKDB_TYPES
}
