package storehouse

import (
	"fmt"
	"server/dao"
)

type CommodityGenreService struct{}

func (cgs *CommodityGenreService) QueryAllCommodityGenre() ([]dao.CommodityGenre, error) {
	return dao.QueryAllCommodityGenres()
}

func (cgs *CommodityGenreService) CreateCommodityGenre(cg dao.CommodityGenre) error {
	return cg.CreateCommodityGenre()
}

func (cgs *CommodityGenreService) UpdateCommodityGenre(cg dao.CommodityGenre) error {
	return cg.UpdateCommodityGenre()
}

func (cgs *CommodityGenreService) DeleteCommodityGenre(cg dao.CommodityGenre) error {
	commodity, err := dao.QueryCommodityByGenre(int(cg.ID))
	if err != nil {
		return err
	}
	if len(commodity) > 0 {
		return fmt.Errorf("数据已被使用")
	}

	return cg.DeleteCommodityGenre()
}
