// Package service 业务逻辑层
package service

import (
	"server/modules/yx/entity"
	"server/modules/yx/mapper"

	"github.com/google/uuid"
)

type YxUserScoreService struct {
	mapper *mapper.YxUserScoreMapper
}

func NewYxUserScoreService() *YxUserScoreService {
	return &YxUserScoreService{mapper: mapper.NewYxUserScoreMapper()}
}

func (s *YxUserScoreService) List(page, size int) ([]entity.YxUserScore, int64, error) {
	return s.mapper.FindAll(page, size)
}

func (s *YxUserScoreService) GetByID(id string) (*entity.YxUserScore, error) {
	return s.mapper.FindByID(id)
}

func (s *YxUserScoreService) Create(item *entity.YxUserScore) error {
	item.ID = uuid.New().String()
	return s.mapper.Create(item)
}

func (s *YxUserScoreService) Update(item *entity.YxUserScore) error {
	return s.mapper.Update(item)
}

func (s *YxUserScoreService) UpdateFields(id string, fields map[string]interface{}) error {
	return s.mapper.UpdateFields(id, fields)
}

func (s *YxUserScoreService) UpdateFieldsByEntity(item *entity.YxUserScore, fields map[string]interface{}) error {
	return s.mapper.UpdateFieldsByMultiCondition(item, fields)
}

func (s *YxUserScoreService) Delete(id string) error {
	return s.mapper.Delete(id)
}

func (s *YxUserScoreService) BatchCreate(items []entity.YxUserScore) error {
	for i := range items {
		items[i].ID = uuid.New().String()
	}
	return s.mapper.BatchCreate(items, 100)
}

func (s *YxUserScoreService) BatchUpdate(items []entity.YxUserScore) error {
	return s.mapper.BatchUpdate(items)
}

func (s *YxUserScoreService) BatchUpsert(items []entity.YxUserScore, updateColumns []string) error {
	for i := range items {
		if items[i].ID == "" {
			items[i].ID = uuid.New().String()
		}
	}
	return s.mapper.BatchUpsert(items, updateColumns)
}

func (s *YxUserScoreService) BatchDelete(ids []string) error {
	return s.mapper.BatchDelete(ids)
}
