package services

import (
	"sparrow/pkg/models"
	"sparrow/services/knowoapi/model"
)

// SubDeviceService SubDevice service接口
type SubDeviceService interface {
	// GetSubDeviceCount 获取设备下子设备总数
	GetSubDeviceCount(deviceCode string) (int, error)
	// GetSubDevices 获取子设备列表
	GetSubDevices(deviceCode string, pi, ps int) ([]*models.SubDevice, int, error)
}

type subDeviceService struct {
	models *model.All
}

// NewSubDeviceService create SubDevice manager
func NewSubDeviceService(models *model.All) SubDeviceService {
	return subDeviceService{
		models: models,
	}
}
func (a subDeviceService) GetSubDevices(deviceCode string, pi, ps int) ([]*models.SubDevice, int, error) {

	data, total, err := a.models.SubDevice.GetSubDevices(deviceCode, pi, ps)

	if err != nil {
		return nil, 0, err
	}

	return data, total, nil
}
func (a subDeviceService) GetSubDeviceCount(vendorid string) (int, error) {
	return a.models.SubDevice.GetSubDeviceCount(vendorid)
}
