package activity

import (
	"context"

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

// ListIssues 查询活动期列表（支持分页）
// 参数: activityID 活动ID, page 页码, pageSize 每页数量
// 返回: 期集合、总数与错误
func (s *service) ListIssues(ctx context.Context, activityID int64, page, pageSize int) (items []*model.ActivityIssues, total int64, err error) {
    q := s.readDB.ActivityIssues.WithContext(ctx).ReadDB().Where(s.readDB.ActivityIssues.ActivityID.Eq(activityID)).Where(s.readDB.ActivityIssues.Status.Neq(2))
	total, err = q.Count()
	if err != nil {
		return nil, 0, err
	}
	if page <= 0 {
		page = 1
	}
	if pageSize <= 0 {
		pageSize = 20
	}
	if pageSize > 100 {
		pageSize = 100
	}
	items, err = q.Order(s.readDB.ActivityIssues.Sort.Desc()).Offset((page - 1) * pageSize).Limit(pageSize).Find()
	if err != nil {
		return nil, 0, err
	}
	return items, total, nil
}
