package drawdb

// DrawDBSchema represents the complete DrawDB JSON structure
type DrawDBSchema struct {
	Tables        []*DrawDBTable        `json:"tables" yaml:"tables" xml:"tables"`
	Relationships []*DrawDBRelationship `json:"relationships" yaml:"relationships" xml:"relationships"`
	Notes         []*DrawDBNote         `json:"notes,omitempty" yaml:"notes,omitempty" xml:"notes,omitempty"`
	SubjectAreas  []*DrawDBArea         `json:"subjectAreas,omitempty" yaml:"subjectAreas,omitempty" xml:"subjectAreas,omitempty"`
}

// DrawDBTable represents a table in DrawDB format
type DrawDBTable struct {
	ID      int            `json:"id" yaml:"id" xml:"id"`
	Name    string         `json:"name" yaml:"name" xml:"name"`
	Schema  string         `json:"schema,omitempty" yaml:"schema,omitempty" xml:"schema,omitempty"`
	Comment string         `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
	Color   string         `json:"color" yaml:"color" xml:"color"`
	X       int            `json:"x" yaml:"x" xml:"x"`
	Y       int            `json:"y" yaml:"y" xml:"y"`
	Fields  []*DrawDBField `json:"fields" yaml:"fields" xml:"fields"`
	Indexes []*DrawDBIndex `json:"indexes,omitempty" yaml:"indexes,omitempty" xml:"indexes,omitempty"`
}

// DrawDBField represents a column/field in DrawDB format
type DrawDBField struct {
	ID        int    `json:"id" yaml:"id" xml:"id"`
	Name      string `json:"name" yaml:"name" xml:"name"`
	Type      string `json:"type" yaml:"type" xml:"type"`
	Default   string `json:"default,omitempty" yaml:"default,omitempty" xml:"default,omitempty"`
	Check     string `json:"check,omitempty" yaml:"check,omitempty" xml:"check,omitempty"`
	Primary   bool   `json:"primary" yaml:"primary" xml:"primary"`
	Unique    bool   `json:"unique" yaml:"unique" xml:"unique"`
	NotNull   bool   `json:"notNull" yaml:"notNull" xml:"notNull"`
	Increment bool   `json:"increment" yaml:"increment" xml:"increment"`
	Comment   string `json:"comment,omitempty" yaml:"comment,omitempty" xml:"comment,omitempty"`
}

// DrawDBIndex represents an index in DrawDB format
type DrawDBIndex struct {
	ID     int    `json:"id" yaml:"id" xml:"id"`
	Name   string `json:"name" yaml:"name" xml:"name"`
	Unique bool   `json:"unique" yaml:"unique" xml:"unique"`
	Fields []int  `json:"fields" yaml:"fields" xml:"fields"` // Field IDs
}

// DrawDBRelationship represents a relationship in DrawDB format
type DrawDBRelationship struct {
	ID               int    `json:"id" yaml:"id" xml:"id"`
	Name             string `json:"name" yaml:"name" xml:"name"`
	StartTableID     int    `json:"startTableId" yaml:"startTableId" xml:"startTableId"`
	EndTableID       int    `json:"endTableId" yaml:"endTableId" xml:"endTableId"`
	StartFieldID     int    `json:"startFieldId" yaml:"startFieldId" xml:"startFieldId"`
	EndFieldID       int    `json:"endFieldId" yaml:"endFieldId" xml:"endFieldId"`
	Cardinality      string `json:"cardinality" yaml:"cardinality" xml:"cardinality"` // "One to one", "One to many", "Many to one"
	UpdateConstraint string `json:"updateConstraint,omitempty" yaml:"updateConstraint,omitempty" xml:"updateConstraint,omitempty"`
	DeleteConstraint string `json:"deleteConstraint,omitempty" yaml:"deleteConstraint,omitempty" xml:"deleteConstraint,omitempty"`
}

// DrawDBNote represents a note in DrawDB format
type DrawDBNote struct {
	ID      int    `json:"id" yaml:"id" xml:"id"`
	Content string `json:"content" yaml:"content" xml:"content"`
	Color   string `json:"color" yaml:"color" xml:"color"`
	X       int    `json:"x" yaml:"x" xml:"x"`
	Y       int    `json:"y" yaml:"y" xml:"y"`
}

// DrawDBArea represents a subject area/grouping in DrawDB format
type DrawDBArea struct {
	ID     int    `json:"id" yaml:"id" xml:"id"`
	Name   string `json:"name" yaml:"name" xml:"name"`
	Color  string `json:"color" yaml:"color" xml:"color"`
	X      int    `json:"x" yaml:"x" xml:"x"`
	Y      int    `json:"y" yaml:"y" xml:"y"`
	Width  int    `json:"width" yaml:"width" xml:"width"`
	Height int    `json:"height" yaml:"height" xml:"height"`
}
