package types

import (
	"git.loafle.net/overflow/overflow_probe/discovery/discovery/types/timestamp"
)

type DiscoveryService struct {
	ID          int                 `json:"id,omitempty"`
	CreateDate  timestamp.Timestamp `json:"createDate,omitempty"`
	UpdateDate  timestamp.Timestamp `json:"updateDate,omitempty"`
	Port        *DiscoveryPort      `json:"-"`
	PortType    string              `json:"portType"` /*tls or normal*/
	ServiceName string              `json:"serviceName"`

	Target bool `json:"target,omitempty"`
}

func NewService(ptype string, serviceName string, port *DiscoveryPort) *DiscoveryService {
	service := &DiscoveryService{PortType: ptype, ServiceName: serviceName, Port: port}
	return service
}

const (
	DIRECTION_SEND = "Send"
	DIRECTION_RECV = "Recv"
)

type ServiceScanHistory struct {
	ID          int                 `json:"id,omitempty"`
	CreateDate  timestamp.Timestamp `json:"createDate,omitempty"`
	Port        *DiscoveryPort      `json:"-"`
	ServiceName string              `json:"serviceName"`
	Direction   string              `json:"direction"`
	Packet      []byte              `json:"packet"`
}

func NewServiceScanHistory(port *DiscoveryPort, serviceName string, direction string, packet []byte) *ServiceScanHistory {
	return &ServiceScanHistory{
		CreateDate:  timestamp.Now(),
		Port:        port,
		ServiceName: serviceName,
		Direction:   direction,
		Packet:      packet,
	}
}
