package activity

import (
	"context"

	"bindbox-game/internal/repository/mysql/model"
)

func (s *service) CreateActivity(ctx context.Context, in CreateActivityInput) (*model.Activities, error) {
	item := &model.Activities{
		Name:               in.Name,
		Banner:             in.Banner,
		ActivityCategoryID: in.ActivityCategoryID,
		Status:             in.Status,
		PriceDraw:          in.PriceDraw,
		IsBoss:             in.IsBoss,
	}

	if in.StartTime != nil {
		item.StartTime = *in.StartTime
	}
	if in.EndTime != nil {
		item.EndTime = *in.EndTime
	}

	do := s.writeDB.Activities.WithContext(ctx)
	if in.StartTime == nil {
		do = do.Omit(s.writeDB.Activities.StartTime)
	}
	if in.EndTime == nil {
		do = do.Omit(s.writeDB.Activities.EndTime)
	}
	err := do.Create(item)
	if err != nil {
		return nil, err
	}
	return item, nil
}
