// Package service 业务逻辑层
package service

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

	"github.com/google/uuid"
)

type YxVolunteerService struct {
	mapper *mapper.YxVolunteerMapper
}

func NewYxVolunteerService() *YxVolunteerService {
	return &YxVolunteerService{mapper: mapper.NewYxVolunteerMapper()}
}

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

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

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

func (s *YxVolunteerService) Update(item *entity.YxVolunteer) error {
	return s.mapper.Update(item)
}

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

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

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

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

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