package model

import (
	v1 "github.com/go-nunu/nunu-layout-advanced/api/v1"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"time"
)

type WebForwarding struct {
	Id                   int `gorm:"primary"`
	HostId               int `gorm:"not null"`
	WafWebId             int `gorm:"not null"` // 修改为与TCP转发一致的命名
	Tag                  string `gorm:"null"`
	Port                 string `gorm:"not null"`
	Domain               string `gorm:"null"`
	CustomHost           string `gorm:"null"`
	WafGatewayGroupId    int `gorm:"not null"`
	WebLimitRuleId       int `gorm:"not null"`
	CcCount              int `gorm:"null"`
	CcDuration           string `gorm:"null"`
	CcBlockCount         int `gorm:"null"`
	CcBlockDuration      string `gorm:"null"`
	Cc4xxCount           int `gorm:"column:cc_4xx_count;null"`
	Cc4xxDuration        string `gorm:"column:cc_4xx_duration;null"`
	Cc4xxBlockCount      int `gorm:"column:cc_4xx_block_count;null"`
	Cc4xxBlockDuration   string `gorm:"column:cc_4xx_block_duration;null"`
	Cc5xxCount           int `gorm:"column:cc_5xx_count;null"`
	Cc5xxDuration        string `gorm:"column:cc_5xx_duration;null"`
	Cc5xxBlockCount      int `gorm:"column:cc_5xx_block_count;null"`
	Cc5xxBlockDuration   string `gorm:"column:cc_5xx_block_duration;null"`
	IsHttps              int `gorm:"null"`
	Comment              string `gorm:"null"`
	HttpsCert             string `gorm:"null"`
	HttpsKey             string `gorm:"null"`
	CreatedAt            time.Time
	UpdatedAt            time.Time
}

func (m *WebForwarding) TableName() string {
    return "shd_waf_web"
}

// WebForwardingRule 用于存储Web转发规则
type WebForwardingRule struct {
	ID          primitive.ObjectID `bson:"_id,omitempty"`
	Uid         int                `bson:"uid" json:"uid"`
	HostId      int                `bson:"host_id" json:"host_id"`
	WebId       int                `bson:"web_id" json:"web_id"`
	BackendList []v1.BackendList   `bson:"backend_list" json:"backend_list"`
	AllowIpList []string           `bson:"allow_ip_list" json:"allow_ip_list"`
	DenyIpList  []string           `bson:"deny_ip_list" json:"deny_ip_list"`
	AccessRule  string             `bson:"access_rule" json:"access_rule"`
	CreatedAt   time.Time          `bson:"created_at" json:"created_at"`
	UpdatedAt   time.Time          `bson:"updated_at" json:"updated_at"`
}

func (m *WebForwardingRule) CollectionName() string {
	return "web_forwarding_rules"
}
