package activity

import (
	"context"
	"time"
)

func (s *service) ModifyActivity(ctx context.Context, id int64, in ModifyActivityInput) error {
	item, err := s.readDB.Activities.WithContext(ctx).Where(s.readDB.Activities.ID.Eq(id)).First()
	if err != nil {
		return err
	}
	if in.Name != "" {
		item.Name = in.Name
	}
	if in.Banner != "" {
		item.Banner = in.Banner
	}
	if in.ActivityCategoryID != 0 {
		item.ActivityCategoryID = in.ActivityCategoryID
	}
	if in.Status != 0 {
		item.Status = in.Status
	}
	if in.PriceDraw != 0 {
		item.PriceDraw = in.PriceDraw
	}
	if in.IsBoss != 0 {
		item.IsBoss = in.IsBoss
	}
	if in.StartTime != nil {
		item.StartTime = *in.StartTime
	}
	if in.EndTime != nil {
		item.EndTime = *in.EndTime
	}
	item.UpdatedAt = time.Now()
	return s.writeDB.Activities.WithContext(ctx).Save(item)
}
