// Package service 业务逻辑层
package service

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

	"github.com/google/uuid"
)

type YxVolunteerRecordService struct {
	mapper *mapper.YxVolunteerRecordMapper
}

func NewYxVolunteerRecordService() *YxVolunteerRecordService {
	return &YxVolunteerRecordService{mapper: mapper.NewYxVolunteerRecordMapper()}
}

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

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

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

func (s *YxVolunteerRecordService) Update(item *entity.YxVolunteerRecord) error {
	return s.mapper.Update(item)
}

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

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

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

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

func (s *YxVolunteerRecordService) BatchUpsert(items []entity.YxVolunteerRecord, 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 *YxVolunteerRecordService) BatchDelete(ids []string) error {
	return s.mapper.BatchDelete(ids)
}
