package service

import (
	"iot_manager_service/app/device/dao"
)

var UtilService = new(utilService)

type utilService struct{}

func (s *utilService) GetDeviceVendor(tenantId string, deviceType int) ([]dao.DeviceVendor, error) {
	// 创建查询实例
	device := &dao.DeviceVendor{
		TenantId:   tenantId,
		DeviceType: deviceType,
	}
	vendors, err := device.GetVendor()
	if err != nil {
		return nil, err
	}
	return vendors, nil
}

func (s *utilService) GetDeviceBrand(tenantId string, deviceType int) ([]dao.DeviceVendor, error) {
	// 创建查询实例
	device := &dao.DeviceVendor{
		TenantId:   tenantId,
		DeviceType: deviceType,
	}
	vendors, err := device.GetBrand()
	if err != nil {
		return nil, err
	}
	return vendors, nil
}

func (s *utilService) GetDeviceModel(tenantId string, deviceType, parentId int) ([]dao.DeviceVendor, error) {
	// 创建查询实例
	device := &dao.DeviceVendor{
		TenantId:   tenantId,
		DeviceType: deviceType,
		ParentId:   parentId,
	}
	vendors, err := device.GetModel()
	if err != nil {
		return nil, err
	}
	return vendors, nil
}

func (s *utilService) GetTenantCode(tenantId string) (*dao.TenantCode, error) {
	// 创建查询实例
	device := &dao.TenantCode{
		TenantId: tenantId,
	}
	tenantCode, err := device.GetTenantCode()
	if err != nil {
		return nil, err
	}
	return &tenantCode, nil
}

func (s *utilService) GetDeviceVendorList(tenantId string, venderValue string, deviceType, offset, limit int) ([]dao.DeviceVendor, int64, error) {
	device := dao.DeviceVendor{
		TenantId:    tenantId,
		VendorValue: venderValue,
		DeviceType:  deviceType,
	}
	return device.GetDeviceVendors(offset, limit)
}

func (s *utilService) GetRemoveVendor(id int) error {
	device := dao.DeviceVendor{
		ID: id,
	}
	return device.Remove()
}
