package reaper

import "time"

type Language struct {
	ID   uint   `gorm:",unique;autoIncrement:true"`
	Code string `gorm:"primaryKey;index:,unique"`
	ISO  *string
}

type Genre struct {
	ID     uint   `gorm:",unique;autoIncrement:true"`
	RawTag string `gorm:"index:,unique"`
	Tag    *string
	Name   *string
}

type Author struct {
	ID         uint   `gorm:"primaryKey;index:,unique;autoIncrement:true"`
	Key        string `gorm:",unique"`
	FirstName  string
	MiddleName *string
	LastName   *string
	IsBanned   *bool
	BanReason  *string
	Books      []Book `gorm:"many2many:BookAuthor"`
}

type User struct {
	ID       uint   `gorm:"primaryKey"`
	Username string `gorm:"autoIncrement:false;index:,unique"`
	Avatar   *string
	Name     *string
	Admin    bool
	Lang     *string
	Language *Language `gorm:"foreignKey:Lang"`
	LastSeen time.Time
	Created  time.Time
	Password string
	OTPToken *string
	//Favorites   []Book `gorm:"many2many:FavoriteBook;ForeignKey:username"`
	BookShelf []ReaderBook
}

type Translator struct {
	ID         uint   `gorm:"primaryKey;index:,unique;autoIncrement:true"`
	Key        string `gorm:",unique"`
	FirstName  string
	MiddleName *string
	LastName   *string
}

type Sequence struct {
	ID   uint   `gorm:",unique;autoIncrement:true"`
	Name string `gorm:"primaryKey;index:,unique"`
}

type Publisher struct {
	ID   uint   `gorm:",unique;autoIncrement:true"`
	Name string `gorm:"primaryKey;index:,unique"`
}

type Book struct {
	ID           uint64 `gorm:"primaryKey"`
	Title        string
	Authors      []Author `gorm:"many2many:BookAuthor;References:ID"`
	Lang         *string
	Language     Language `gorm:"foreignKey:Lang"`
	Genre        *[]Genre `gorm:"many2many:BookGenre;References:RawTag"`
	Description  *string  `gorm:"type:text"`
	HasCover     bool
	IsTranslated bool
	Translators  *[]Translator `gorm:"many2many:BookTranslator;References:ID"`
	SrcLang      *string
	SrcLanguage  Language `gorm:"foreignKey:SrcLang"`
	Sequence     *string
	SequenceID   *Sequence `gorm:"foreignKey:Sequence"`
	SequenceBook *int
	Year         *int
	Publisher    *string
	PublisherID  *Publisher `gorm:"foreignKey:Publisher"`
	Isbn         *string
	Downloads    int `gorm:"default:0"`
	Views        int `gorm:"default:0"`
	SymbolsCount *int
	PagesCount   *int // pdf
	Size         int
	Hash         *string
	Bookcase     *string
	Filename     string
	// FiletypeID    uint
	Filetype      string
	UploadedByID  *uint
	UploadedBy    *User
	UploadedAt    *time.Time
	Collections   []Collection `gorm:"many2many:CollectionBook;"`
	ExternalCover *string
}

//	type Filetype struct {
//		ID       uint   `gorm:"primaryKey"`
//		Filetype string `gorm:"uniqueIndex"`
//		Name     string
//	}
type ReaderBook struct {
	ID       uint `gorm:"primaryKey"`
	UserID   uint
	BookID   uint
	Book     Book `gorm:"foreignKey:BookID"`
	Progress float64
	LastRead time.Time
}
type Collection struct {
	ID       uint   `gorm:"primaryKey"`
	Link     string `gorm:"uniqueIndex"`
	Name     string
	UserID   uint
	Creator  User   `gorm:"foreignKey:UserID"`
	Books    []Book `gorm:"many2many:CollectionBook;"`
	Created  time.Time
	Modified time.Time
}
