// Package service 业务逻辑层
package service

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

	"github.com/google/uuid"
)

type YxSchoolMajorService struct {
	mapper *mapper.YxSchoolMajorMapper
}

func NewYxSchoolMajorService() *YxSchoolMajorService {
	return &YxSchoolMajorService{mapper: mapper.NewYxSchoolMajorMapper()}
}

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

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

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

func (s *YxSchoolMajorService) Update(item *entity.YxSchoolMajor) error {
	return s.mapper.Update(item)
}

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

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

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

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

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