package backend

import (
	"dhcp/code"
	"dhcp/internal/dao"
	"dhcp/model"
	"dhcp/result"
)

func AddDHCPInfo(dhcpInfo model.DHCP) result.Result {
	err := dao.AddDHCP(dhcpInfo)
	return result.Result{
		Status: err == nil,
		Code:   code.SUCCESS,
		Msg:    "添加成功",
	}
}

func GetDHCPInfoByMac(mac string) result.Result {
	dhcpInfo, err := dao.GetDHCPByMac(mac)
	return result.Result{
		Status: err == nil,
		Code:   code.SUCCESS,
		Data:   dhcpInfo,
	}
}

func GetDHCPInfo() result.Result {
	dhcpInfo, err := dao.GetDHCP()
	return result.Result{
		Status: err == nil,
		Code:   code.SUCCESS,
		Data:   dhcpInfo,
	}
}

func UpdateDHCPInfo(dhcpInfo model.DHCP) result.Result {
	err := dao.UpdateDHCP(dhcpInfo)
	return result.Result{
		Status: err == nil,
		Code:   code.SUCCESS,
		Msg:    "更新成功",
	}
}

func DeleteDHCPInfo(mac string) result.Result {
	err := dao.DeleteDHCP(mac)
	return result.Result{
		Status: err == nil,
		Code:   code.SUCCESS,
		Msg:    "删除成功",
	}
}
