package services

import (
	"github.com/gogf/gf/util/guid"
	"sparrow/pkg/models"
	"sparrow/services/knowoapi/model"
)

// SensorService 业务接口
type SensorService interface {
	Create(*models.Sensor) error
	Update(*models.Sensor) (models.Sensor, error)
	Delete(*models.Sensor) error
	GetSensorInfo(pid uint) (models.Sensor, error)
	// 获取产品的传感器列表
	// 参数 ： 产品id, pi, ps, 名称，标签
	GetProductSensors(productid uint, pi, ps int, name, label string) ([]models.Sensor, int, error)
}

type sensorService struct {
	model *model.All
}

// NewSensorService new sensor manager
func NewSensorService(model *model.All) SensorService {
	return sensorService{
		model: model,
	}
}

func (a sensorService) Create(sensor *models.Sensor) error {
	sensor.RecordId = guid.S()
	return a.model.Sensor.Create(sensor)
}
func (a sensorService) Delete(sensor *models.Sensor) error {
	return a.model.Sensor.Delete(sensor)
}
func (a sensorService) Update(sensor *models.Sensor) (models.Sensor, error) {
	return a.model.Sensor.Update(sensor)
}
func (a sensorService) GetProductSensors(proid uint, pi, ps int, name, label string) ([]models.Sensor, int, error) {
	return a.model.Sensor.GetProductSensors(proid, pi, ps, name, label)
}
func (a sensorService) GetSensorInfo(sid uint) (models.Sensor, error) {
	return a.model.Sensor.GetSensorInfo(sid)
}
