package schema

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

// Defining the `Activity` struct.
type Activity struct {
	util.BaseModel
	Title        string     `json:"title" gorm:"size:128;not null;index;comment:标题"`
	Cover        string     `json:"cover" gorm:"size:2048;not null;comment:封面"`
	Images       *[]string  `json:"images" gorm:"serializer:json;comment:详图数组"`
	StartAt      *time.Time `json:"startAt" gorm:"not null;comment:开始时间"`
	EndAt        *time.Time `json:"endAt" gorm:"not null;comment:结束时间"`
	EndSignupAt  *time.Time `json:"endSignupAt" gorm:"not null;comment:最晚报名时间"`
	MaxSignupNum int        `json:"maxSignupNum" gorm:"not null;comment:最大报名人数"`
	SignupNum    int        `json:"signupNum" gorm:"not null;default:0;comment:当前报名人数"`
	Address      string     `json:"address" gorm:"size:1024;not null;comment:活动地址"`
	Content      string     `json:"content" gorm:"type:text;not null;comment:活动详情"`
	Point        int        `json:"point" gorm:"not null;default:0;comment:活动所需积分"`
	AreaID       uint       `json:"areaId" gorm:"index;comment:城市id"`
	Status       string     `json:"status" gorm:"size:20;index;comment:状态"`
}

// Defining the query parameters for the `Activity` struct.
type ActivityQueryParam struct {
	util.PaginationParam
	LikeTitle string `form:"title" `
	Status    string `form:"status" `
	AreaID    uint   `form:"areaId"`
}

// Defining the query options for the `Activity` struct.
type ActivityQueryOptions struct {
	util.QueryOptions
}

// Defining the query result for the `Activity` struct.
type ActivityQueryResult struct {
	Data       Activities
	PageResult *util.PaginationResult
}

// Defining the slice of `Activity` struct.
type Activities []*Activity

// Defining the data structure for creating a `Activity` struct.
type ActivityForm struct {
	Title        string     `json:"title" `
	Cover        string     `json:"cover" `
	Images       *[]string  `json:"images" `
	StartAt      *time.Time `json:"startAt" `
	EndAt        *time.Time `json:"endAt" `
	EndSignupAt  *time.Time `json:"endSignupAt" `
	MaxSignupNum int        `json:"maxSignupNum" `
	SignupNum    int        `json:"signupNum"`
	Address      string     `json:"address" `
	Content      string     `json:"content"`
	Point        int        `json:"point" `
	Status       string     `json:"status" `
	AreaID       uint       `json:"areaId" `
}

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

// Convert `ActivityForm` to `Activity` object.
func (a *ActivityForm) FillTo(activity *Activity) error {
	activity.Title = a.Title
	activity.Cover = a.Cover
	activity.Images = a.Images
	activity.StartAt = a.StartAt
	activity.EndAt = a.EndAt
	activity.AreaID = a.AreaID
	activity.EndSignupAt = a.EndSignupAt
	activity.MaxSignupNum = a.MaxSignupNum
	activity.SignupNum = a.SignupNum
	activity.Address = a.Address
	activity.Content = a.Content
	activity.Point = a.Point
	activity.Status = a.Status
	return nil
}
