package admin

import (
	"server/dao"
	"server/model/common/response"
)

type DeviceGenreService struct{}

func (dgs *DeviceGenreService) QueryAllDeviceGenres() ([]response.DeviceGenres, error) {
	genres, err := dao.QueryAllDeviceGenres()
	if err != nil {
		return nil, err
	}
	data, err := dao.QueryDeviceNumberByGenre()
	if err != nil {
		return nil, err
	}

	data1 := []response.DeviceGenres{}

	for _, genre := range genres {
		for _, i3 := range data {
			if int(genre.ID) == i3.Genre {
				deviceGenres := response.DeviceGenres{
					genre,
					i3.Count,
				}
				data1 = append(data1, deviceGenres)
			}
		}
	}

	return data1, err
}

func (dgs *DeviceGenreService) CreateDeviceGenre(genre dao.DeviceGenre) error {
	return genre.CreateDeviceGenre()
}

func (dgs *DeviceGenreService) UpdateDeviceGenre(genre dao.DeviceGenre) error {
	return genre.UpdateDeviceGenre()
}

func (dgs *DeviceGenreService) DeleteDeviceGenre(id int) error {
	return dao.DeleteDeviceGenre(id)
}
