package model

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

type Book struct {
	g.Meta          `orm:"table:books"`
	Id              int64    `json:"id"              orm:"id"`
	AuthorId        int64    `json:"authorId"        orm:"author_id"`
	Author          Author   `json:"author"          orm:"with:id = author_id"`
	CategoryId      int64    `json:"categoryId"      orm:"category_id"`
	Category        Category `json:"category"        orm:"with:id = category_id"`
	Title           string   `json:"title"           orm:"title"`
	CoverUrl        string   `json:"coverUrl"        orm:"cover_url"`
	Description     string   `json:"description"     orm:"description"`
	Status          int      `json:"status"          orm:"status"`
	WordsCount      int      `json:"wordsCount"      orm:"words_count"`
	ChaptersCount   int      `json:"chaptersCount"   orm:"chapters_count"`
	LatestChapterId int64    `json:"latestChapterId" orm:"latest_chapter_id"`
	Rating          float64  `json:"rating"          orm:"rating"`
	ReadCount       int64    `json:"readCount"       orm:"read_count"`
	CurrentReaders  int64    `json:"currentReaders"  orm:"current_readers"`
	Tags            string   `json:"tags"            orm:"tags"`
	IsRecommended   int      `json:"isRecommended"   orm:"is_recommended"`
	IsFeatured      int      `json:"isFeatured"      orm:"is_featured"`
	IsHot           int      `json:"isHot"           orm:"is_hot"`
	Language        string   `json:"language"        orm:"language"`
}
type SimpleBook struct {
	g.Meta   `orm:"table:books"`
	Id       int64  `json:"id"              orm:"id"`
	AuthorId int64  `json:"authorId"        orm:"author_id"`
	Author   Author `json:"author"          orm:"with:id = author_id"`
	Title    string `json:"title"           orm:"title"`
}

// App作者信息结构体
type AppAuthor struct {
	g.Meta  `orm:"table:authors"`
	Id      int64  `json:"id"      orm:"id"`
	UserId  int64  `json:"-"       orm:"user_id"`
	PenName string `json:"penName" orm:"pen_name"`
	Bio     string `json:"bio"     orm:"bio"`
	Status  int    `json:"status"  orm:"status"`
}

type BookListIn struct {
	Page          int
	Size          int
	Title         string
	CategoryId    int64
	AuthorId      int64
	Status        int
	IsRecommended int
	Sort          string
}
type BookListOut struct {
	Total int
	List  []Book
}

type BookAddIn struct {
	AuthorId      int64
	CategoryId    int64
	Title         string
	CoverUrl      string
	Description   string
	Status        int
	Tags          string
	IsRecommended int
	IsFeatured    int
	Language      string
}
type BookEditIn struct {
	Id            int64
	AuthorId      int64
	CategoryId    int64
	Title         string
	CoverUrl      string
	Description   string
	Status        int
	Tags          string
	IsRecommended int
	IsFeatured    int
	Language      string
}
type BookDelIn struct {
	Id int64
}

type BookCRUDOut struct {
	Success bool
}

type BookHistoryRemoveOut struct {
	Success bool `json:"success" dc:"是否成功"`
}

// App 书籍列表项结构体
type BookAppItem struct {
	g.Meta          `orm:"table:books"`
	Id              int64       `json:"id"               dc:"书籍ID"           orm:"id"`
	CoverUrl        string      `json:"coverUrl"         dc:"封面图"           orm:"cover_url"`
	Rating          float64     `json:"rating"           dc:"评分"             orm:"rating"`
	Title           string      `json:"title"            dc:"标题"             orm:"title"`
	Description     string      `json:"description"      dc:"简介"             orm:"description"`
	AuthorId        int64       `json:"authorId"         dc:"作者ID"           orm:"author_id"`
	Author          AppAuthor   `json:"author"           dc:"作者信息"         orm:"with:id = author_id"`
	IsFeatured      int         `json:"isFeatured"       dc:"是否精选"         orm:"is_featured"`
	Language        string      `json:"language"         dc:"语言"             orm:"language"`
	CategoryId      int64       `json:"categoryId"       dc:"分类ID"           orm:"category_id"`
	Category        Category    `json:"category"         dc:"分类信息"         orm:"with:id = category_id"`
	Status          int         `json:"status"           dc:"状态"             orm:"status"`
	WordsCount      int         `json:"wordsCount"       dc:"字数"             orm:"words_count"`
	ChaptersCount   int         `json:"chaptersCount"    dc:"章节数"           orm:"chapters_count"`
	LatestChapterId int64       `json:"latestChapterId"  dc:"最新章节ID"        orm:"latest_chapter_id"`
	ReadCount       int64       `json:"readCount"        dc:"阅读人数"          orm:"read_count"`
	CurrentReaders  int64       `json:"currentReaders"   dc:"在读人数"          orm:"current_readers"`
	Tags            string      `json:"tags"             dc:"标签"             orm:"tags"`
	IsRecommended   int         `json:"isRecommended"    dc:"是否推荐"          orm:"is_recommended"`
	IsHot           int         `json:"isHot"            dc:"是否热门"          orm:"is_hot"`
	CreatedAt       *gtime.Time `json:"createdAt"       dc:"创建时间"          orm:"created_at"`
	UpdatedAt       *gtime.Time `json:"updatedAt"       dc:"更新时间"          orm:"updated_at"`
	HasRated        bool        `json:"hasRated"         dc:"当前用户是否已评分"`
	MyRating        float64     `json:"myRating"         dc:"当前用户评分（未评分为0）"`
	IsInBookshelf   bool        `json:"isInBookshelf"    dc:"当前用户是否已加入书架"`
}

// App 书籍列表查询输入参数
type BookAppListIn struct {
	Page          int    `json:"page" dc:"页码"`
	Size          int    `json:"size" dc:"每页数量"`
	IsRecommended bool   `json:"isRecommended" dc:"是否推荐"`
	IsLatest      int    `json:"isLatest" dc:"是否最新"`
	CategoryId    int64  `json:"categoryId" dc:"分类ID"`
	Title         string `json:"title" dc:"书名模糊搜索"`
	UserId        int64  `json:"userId" dc:"用户ID"`
	AuthorId      int    `json:"authorId" dc:"作者ID"`
	IsFeatured    bool   `json:"isFeatured" dc:"是否精选"`
	IsHot         bool   `json:"isHot" dc:"是否热门"`
	Language      string `json:"language" dc:"语言"`
	Sort          string `json:"sort" dc:"排序字段"`
}

// App 书籍列表输出结构体
type BookAppListOut struct {
	Total int           `json:"total" dc:"总数"`
	List  []BookAppItem `json:"list" dc:"书籍列表"`
}

// App 书籍详情查询输入参数
type BookAppDetailIn struct {
	Id     int64 `json:"id" dc:"书籍ID"`
	UserId int64 `json:"userId" dc:"用户ID"`
}

// App 书籍详情输出结构体
type BookAppDetailOut struct {
	Id             int64       `json:"id"               dc:"书籍ID"           orm:"id"`
	CoverUrl       string      `json:"coverUrl"         dc:"封面图"           orm:"cover_url"`
	Rating         float64     `json:"rating"           dc:"评分"             orm:"rating"`
	Title          string      `json:"title"            dc:"标题"             orm:"title"`
	Description    string      `json:"description"      dc:"简介"             orm:"description"`
	AuthorId       int64       `json:"authorId"         dc:"作者ID"           orm:"author_id"`
	Author         AppAuthor   `json:"author"           dc:"作者信息"         orm:"with:id = author_id"`
	IsFeatured     int         `json:"isFeatured"       dc:"是否精选"         orm:"is_featured"`
	Language       string      `json:"language"         dc:"语言"             orm:"language"`
	CategoryId     int64       `json:"categoryId"       dc:"分类ID"           orm:"category_id"`
	Category       Category    `json:"category"         dc:"分类信息"         orm:"with:id = category_id"`
	Status         int         `json:"status"           dc:"状态"             orm:"status"`
	WordsCount     int         `json:"wordsCount"       dc:"字数"             orm:"words_count"`
	ChaptersCount  int         `json:"chaptersCount"    dc:"章节数"           orm:"chapters_count"`
	ReadCount      int64       `json:"readCount"        dc:"阅读人数"          orm:"read_count"`
	CurrentReaders int64       `json:"currentReaders"   dc:"在读人数"          orm:"current_readers"`
	Tags           string      `json:"tags"             dc:"标签"             orm:"tags"`
	IsRecommended  int         `json:"isRecommended"    dc:"是否推荐"          orm:"is_recommended"`
	IsHot          int         `json:"isHot"            dc:"是否热门"          orm:"is_hot"`
	CreatedAt      *gtime.Time `json:"createdAt"        dc:"创建时间"          orm:"created_at"`
	UpdatedAt      *gtime.Time `json:"updatedAt"        dc:"更新时间"          orm:"updated_at"`
	HasRated       bool        `json:"hasRated"         dc:"当前用户是否已评分"`
	MyRating       float64     `json:"myRating"         dc:"当前用户评分（未评分为0）"`
	HasRead        bool        `json:"hasRead"          dc:"是否读过"`
	ReadProgress   int         `json:"readProgress"     dc:"阅读进度百分比"`
	LastChapterId  int64       `json:"lastChapterId"    dc:"最近阅读章节ID"`
	LastReadAt     string      `json:"lastReadAt"       dc:"最近阅读时间"`
	IsInBookshelf  bool        `json:"isInBookshelf"    dc:"当前用户是否已加入书架"`
}

// App 用户评分输入参数
type BookAppRateIn struct {
	BookId int64   `json:"bookId" dc:"书籍ID"`
	UserId int64   `json:"userId" dc:"用户ID"`
	Rating float64 `json:"rating" dc:"评分(1-10分)"`
}

// App 用户评分输出结构体
type BookAppRateOut struct {
	Success bool `json:"success" dc:"是否成功"`
}

// 书籍评分模型
type BookRating struct {
	g.Meta    `orm:"table:book_ratings"`
	Id        int64       `json:"id"        orm:"id"`
	UserId    int64       `json:"userId"    orm:"user_id"`
	BookId    int64       `json:"bookId"    orm:"book_id"`
	Score     float64     `json:"score"     orm:"score"`
	Comment   string      `json:"comment"   orm:"comment"`
	CreatedAt *gtime.Time `json:"createdAt" orm:"created_at"`
}

// 书籍评分输入参数
type BookRatingAddIn struct {
	UserId  int64   `json:"userId"  dc:"用户ID"`
	BookId  int64   `json:"bookId"  dc:"书籍ID"`
	Score   float64 `json:"score"   dc:"评分(1-10分)"`
	Comment string  `json:"comment"  dc:"用户评论"`
}

// 书籍评分输出结构体
type BookRatingCRUDOut struct {
	Success bool `json:"success" dc:"是否成功"`
}

// 我的书籍列表项
// =============================
type MyBookItem struct {
	g.Meta      `orm:"table:books"`
	Id          int64   `json:"id"`
	Title       string  `json:"title"`
	CoverUrl    string  `json:"coverUrl"`
	Description string  `json:"description"`
	Progress    int     `json:"progress" dc:"阅读进度百分比"`
	IsInShelf   bool    `json:"isInShelf" dc:"是否在书架"`
	LastReadAt  string  `json:"lastReadAt" dc:"最近阅读时间"`
	Status      int     `json:"status" dc:"书籍状态"`
	AuthorId    int64   `json:"authorId"`
	CategoryId  int64   `json:"categoryId"`
	Rating      float64 `json:"rating" dc:"评分"`
	HasRated    bool    `json:"hasRated" dc:"当前用户是否已评分"`
	MyRating    float64 `json:"myRating" dc:"当前用户评分（未评分为0）"`
}

// 我的书籍列表查询参数
// =============================
type MyBookListIn struct {
	Type   int // 1-正在读 2-已读完 3-历史记录
	Page   int
	Size   int
	UserId int64
	Sort   string
}

// 我的书籍列表返回
// =============================
type MyBookListOut struct {
	Total int
	List  []MyBookItem
}

// =============================
// 新增：单独修改精选状态和推荐状态
// =============================
type BookSetFeaturedIn struct {
	Id         int64 `json:"id" dc:"书籍ID"`
	IsFeatured int   `json:"isFeatured" dc:"是否精选"`
}

type BookSetRecommendedIn struct {
	Id            int64 `json:"id" dc:"书籍ID"`
	IsRecommended int   `json:"isRecommended" dc:"是否推荐"`
}

type BookSetHotIn struct {
	Id    int64 `json:"id" dc:"书籍ID"`
	IsHot int   `json:"isHot" dc:"是否热门"`
}
