package activity

import (
	"context"
	"time"
)

func (s *service) ModifyIssue(ctx context.Context, issueID int64, in ModifyIssueInput) error {
	item, err := s.readDB.ActivityIssues.WithContext(ctx).Where(s.readDB.ActivityIssues.ID.Eq(issueID)).First()
	if err != nil {
		return err
	}
	if in.IssueNumber != "" {
		item.IssueNumber = in.IssueNumber
	}
	if in.Status != 0 {
		item.Status = in.Status
	}
	if in.Sort != 0 {
		item.Sort = in.Sort
	}
	item.UpdatedAt = time.Now()
	return s.writeDB.ActivityIssues.WithContext(ctx).Save(item)
}
