package dto

import entity "dataapps/internal/entity/sqleditor"

type ShowColumnsRes struct {
	BasicRes
	Data []*entity.Columns `json:"data"`
}

type SchemaSearchRes struct {
	BasicRes
	Data []*SchemaSearchItem `json:"data"`
}

// SchemaSearchType indicates which schema object to search.
// Valid values: "database", "table", "column".
type SchemaSearchType string

const (
	SchemaSearchTypeDatabase SchemaSearchType = "database"
	SchemaSearchTypeTable    SchemaSearchType = "table"
	SchemaSearchTypeColumn   SchemaSearchType = "column"
)

// DatabaseItem represents a database in list/search response, with HasTable indicating if it has any table.
type DatabaseItem struct {
	Name     string `json:"name"`
	HasTable bool   `json:"has_table"`
}

type ListDatabasesInput struct {
	CreatedBy  string
	ProjectID  uint64
	ClusterID  uint64
	Auth0Token string
}

type ListTablesInput struct {
	CreatedBy  string
	ProjectID  uint64
	ClusterID  uint64
	Database   string
	Auth0Token string
}

type ListColumnsInput struct {
	CreatedBy  string
	ProjectID  uint64
	ClusterID  uint64
	Database   string
	Table      string
	Auth0Token string
}

type SearchSchemasInput struct {
	CreatedBy  string
	ProjectID  uint64
	ClusterID  uint64
	Type       SchemaSearchType
	Keyword    string
	Limit      int
	Auth0Token string
}

// SchemaSearchItem is the unified search result across database/table/column.
// - Type=database: only Database is filled
// - Type=table: Database + Table
// - Type=column: Database + Table + Column (+ DataType/Nullable)
type SchemaSearchItem struct {
	Type     SchemaSearchType `json:"type"`
	Database string           `json:"database,omitempty"`
	Table    string           `json:"table,omitempty"`
	Column   string           `json:"column,omitempty"`
	DataType string           `json:"data_type,omitempty"`
	Nullable bool             `json:"nullable,omitempty"`
	// HasTable is set when Type=database, indicating whether the database has any table.
	HasTable bool `json:"has_table,omitempty"`
}
