package schema

import (
	"github.guxuan/haibei/pkg/util"
)

// Defining the `Banner` struct.
type Banner struct {
	util.BaseModel
	Name     string `json:"name" gorm:"size:128;not null;index"`
	Img      string `json:"img" gorm:"size:2048"`
	Sequence int    `json:"sequence" gorm:"index;default:0"`
	Link     string `json:"link" gorm:"size:2048;"`
	AreaID   uint   `json:"areaId" gorm:"index;comment:城市id"`

	Status string `json:"status" gorm:"size:20;index"`
}

// Defining the query parameters for the `Banner` struct.
type BannerQueryParam struct {
	util.PaginationParam
	Status string `form:"status"`
	AreaID uint   `form:"areaId" `
}

// Defining the query options for the `Banner` struct.
type BannerQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Banner` struct.
type BannerQueryResult struct {
	Data       Banners
	PageResult *util.PaginationResult
}

// Defining the slice of `Banner` struct.
type Banners []*Banner

// Defining the data structure for creating a `Banner` struct.
type BannerForm struct {
	Name     string `json:"name" `
	Img      string `json:"img"`
	Sequence int    `json:"sequence"`
	Link     string `json:"link"`
	AreaID   uint   `json:"areaId" `

	Status string `json:"status"`
}

// A validation function for the `BannerForm` struct.
func (a *BannerForm) Validate() error {
	return nil
}

// Convert `BannerForm` to `Banner` object.
func (a *BannerForm) FillTo(banner *Banner) error {
	banner.Name = a.Name
	banner.Img = a.Img
	banner.AreaID = a.AreaID
	banner.Sequence = a.Sequence
	banner.Link = a.Link
	if a.Status != "" {
		banner.Status = a.Status
	} else {
		banner.Status = "active"
	}
	return nil
}
