package schema

import (
	"time"

	"github.com/uptrace/bun"
)

type Sport struct {
	bun.BaseModel `bun:"table:sport"`

	ID        string          `bun:"id,pk"`
	CreatedAt time.Time       `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time       `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version   int             `bun:"version,default:0"`
	Teams     []Team          `bun:"rel:has-many,join:id=sport_id"`
	Positions []FieldPosition `bun:"rel:has-many,join:id=sport_id"`
}

type Team struct {
	bun.BaseModel `bun:"table:team"`

	ID        string    `bun:"id,pk"`
	CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version   int       `bun:"version,default:0"`
	Name      string    `bun:"name"`
	Shortname string    `bun:"short_name"`
	Roosters  []Rooster `bun:"rel:has-many,join:id=team_id"`
	SportID   *string   `bun:"sport_id"`
	Sport     *Sport    `bun:"rel:belongs-to,join:sport_id=id"`
}

type FieldPosition struct {
	bun.BaseModel `bun:"table:field_position"`

	ID        string    `bun:"id,pk"`
	CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version   int       `bun:"version,default:0"`
	Name      string    `bun:"name"`
	Shortname string    `bun:"short_name"`
	SportID   *string   `bun:"sport_id"`
	Sport     *Sport    `bun:"rel:belongs-to,join:sport_id=id"`
	Roosters  []Rooster `bun:"rel:has-many,join:id=position_id"`
}

type Player struct {
	bun.BaseModel `bun:"table:player"`

	ID        string    `bun:"id,pk"`
	CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version   int       `bun:"version,default:0"`
	Firstname string    `bun:"first_name"`
	Lastname  string    `bun:"last_name"`
	Roosters  []Rooster `bun:"rel:has-many,join:id=player_id"`
}

type Rooster struct {
	bun.BaseModel `bun:"table:rooster"`

	ID         string         `bun:"id,pk"`
	CreatedAt  time.Time      `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt  time.Time      `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version    int            `bun:"version,default:0"`
	Year       int            `bun:"year"`
	TeamID     *string        `bun:"team_id"`
	Team       *Team          `bun:"rel:belongs-to,join:team_id=id"`
	PlayerID   *string        `bun:"player_id"`
	Player     *Player        `bun:"rel:belongs-to,join:player_id=id"`
	PositionID *string        `bun:"position_id"`
	Position   *FieldPosition `bun:"rel:belongs-to,join:position_id=id"`
}

type CardSet struct {
	bun.BaseModel `bun:"table:card_set"`

	ID          string    `bun:"id,pk"`
	CreatedAt   time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt   time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version     int       `bun:"version,default:0"`
	Name        string    `bun:"name"`
	ParallelSet bool      `bun:"parallel_set"`
	InsertSet   bool      `bun:"insert_set"`
	VendorID    *string   `bun:"vendor_id"`
	Vendor      *Vendor   `bun:"rel:belongs-to,join:vendor_id=id"`
}

type Vendor struct {
	bun.BaseModel `bun:"table:vendor"`

	ID        string    `bun:"id,pk"`
	CreatedAt time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version   int       `bun:"version,default:0"`
	Name      string    `bun:"name"`
	CardSets  []CardSet `bun:"rel:has-many,join:id=vendor_id"`
}

type Card struct {
	bun.BaseModel `bun:"table:card"`

	ID         string    `bun:"id,pk"`
	CreatedAt  time.Time `bun:"created_date,nullzero,notnull,default:current_timestamp"`
	UpdatedAt  time.Time `bun:"last_modified_date,nullzero,notnull,default:current_timestamp"`
	Version    int       `bun:"version,default:0"`
	CardNumber int       `bun:"card_number"`
	Year       int       `bun:"year"`
	VendorID   *string   `bun:"vendor_id"`
	Vendor     *Vendor   `bun:"rel:belongs-to,join:vendor_id=id"`
	CardSetID  *string   `bun:"card_set_id"`
	CardSet    *CardSet  `bun:"rel:belongs-to,join:card_set_id=id"`
	RoosterID  *string   `bun:"rooster_id"`
	Rooster    *Rooster  `bun:"rel:belongs-to,join:rooster_id=id"`
}
