package services

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

// ProtocalService 业务接口
type ProtocalService interface {
	Create(*models.Protocal) error
	Update(*models.Protocal) (models.Protocal, error)
	Delete(*models.Protocal) error
	GetProtocalInfo(pid uint) (models.Protocal, error)
	// 获取产品的协议列表
	// 参数 ： 产品id, pi, ps, 名称，标签
	GetProductProtocals(productid uint, pi, ps int, name, label string) ([]models.Protocal, int, error)
}

type protocalService struct {
	model *model.All
}

// NewProtocalService new protocal manager
func NewProtocalService(model *model.All) ProtocalService {
	return protocalService{
		model: model,
	}
}

func (a protocalService) Create(ptl *models.Protocal) error {
	ptl.RecordId = guid.S()
	return a.model.Protocal.Create(ptl)
}
func (a protocalService) Delete(ptl *models.Protocal) error {
	return a.model.Protocal.Delete(ptl)
}
func (a protocalService) Update(ptl *models.Protocal) (models.Protocal, error) {
	return a.model.Protocal.Update(ptl)
}
func (a protocalService) GetProductProtocals(proid uint, pi, ps int, name, label string) ([]models.Protocal, int, error) {
	return a.model.Protocal.GetProductProtocals(proid, pi, ps, name, label)
}
func (a protocalService) GetProtocalInfo(pid uint) (models.Protocal, error) {
	return a.model.Protocal.GetProtocalInfo(pid)
}
