package dao

import "server/global"

type Tunnel struct {
	global.GVA_MODEL
	Name  string    `json:"name" gorm:"comment:名称"`
	Users []SysUser `json:"users" gorm:"many2many:user_tunnel"`
}

func (Tunnel) TableName() string {
	return "tunnel"
}

func QueryAllTunnels() (tunnels []Tunnel, err error) {
	err = global.GVA_DB.Find(&tunnels).Error
	return tunnels, err
}

func (t Tunnel) CreateTunnel() error {
	return global.GVA_DB.Create(&t).Error
}

func (t Tunnel) UpdateTunnel() error {
	return global.GVA_DB.Where("id = ?", t.ID).Updates(&t).Error
}

func DeleteTunnel(id int) error {
	return global.GVA_DB.Unscoped().Where("id = ?", id).Delete(&Tunnel{}).Error
}
