package teamspeak

// TextMessage is an incoming notifytextmessage payload.
type TextMessage struct {
	InvokerName   string
	InvokerUID    string
	Message       string
	InvokerGroups []string
	TargetMode    int
	TargetID      uint64
	InvokerID     uint16
}

// ClientMovedEvent is emitted when a client changes channel (notifyclientmoved).
type ClientMovedEvent struct {
	InvokerName     string
	InvokerUID      string
	TargetChannelID uint64
	ReasonID        int
	ID              uint16
	InvokerID       uint16
}

// PokeEvent is emitted when this client is poked (notifyclientpoke).
type PokeEvent struct {
	InvokerName string
	InvokerUID  string
	Message     string
	InvokerID   uint16
}

// ClientLeftViewEvent is emitted when a client leaves view (notifyclientleftview).
type ClientLeftViewEvent struct {
	ReasonMsg string
	ReasonID  int
	ID        uint16
	UID       string
	TargetID  uint16
}

// kickEvent is an internal event for kick notifications (passed through event queue).
type kickEvent struct {
	reason string
}

// VoiceDataEvent is emitted when a voice packet is received from another client.
// Sequence is the sender's uint16 voice-frame packet ID and can be used to order
// or detect gaps independently for each client. IsWhisper reports whether the
// packet used the whisper packet type rather than ordinary channel voice.
type VoiceDataEvent struct {
	Data      []byte
	ClientID  uint16
	Codec     byte
	Sequence  uint16
	IsWhisper bool
}

// ClientInfo holds fields from clientlist / notifycliententerview.
type ClientInfo struct {
	Nickname     string
	UID          string
	ServerGroups []string
	ChannelID    uint64
	Type         int
	ID           uint16
}

// ChannelInfo is one row from channellist.
type ChannelInfo struct {
	Name        string
	Description string
	ID          uint64
	ParentID    uint64
}

// ChannelInfoDetailed is one row from channellist -topic -flags -voice -limits -icon.
// 提供比 ChannelInfo 更丰富的频道属性，用于 UI 展示（密码图标、语音编解码器、人数限制等）。
type ChannelInfoDetailed struct {
	// 基础字段
	ID       uint64
	ParentID uint64
	Order    uint64
	Name     string
	Topic    string

	// 语音相关（-voice）
	Codec           int // 语音编解码器：0=Speex Narrowband, 1=Speex Wideband, 2=Speex UltraWideband, 3=CELT Mono, 4=Opus Voice, 5=Opus Music
	CodecQuality    int // 编解码质量（0-10）
	NeededTalkPower int // 发言所需权限等级

	// 限制（-limits）
	MaxClients                  int // 频道最大客户端数，-1=无限
	MaxFamilyClients            int // 频道族最大客户端数，-1=无限
	IsMaxClientsUnlimited       bool
	IsMaxFamilyClientsUnlimited bool
	IsOrdered                   bool // 频道是否手动排序

	// 标志（-flags）
	IsPermanent       bool
	IsSemiPermanent   bool
	IsDefault         bool
	IsPassword        bool
	HasPassword       bool // 等价于 IsPassword，保留兼容
	NeededModifyPower int  // 修改频道所需权限等级

	// 图标（-icon）
	IconID int64
}

// FileUploadInfo represents the information received when an upload is initialized.
type FileUploadInfo struct {
	FileTransferKey      string
	SeekPosition         uint64
	ClientFileTransferID uint16
	ServerFileTransferID uint16
	Port                 uint16
}

// FileDownloadInfo represents the information received when a download is initialized.
type FileDownloadInfo struct {
	FileTransferKey      string
	Size                 uint64
	ClientFileTransferID uint16
	ServerFileTransferID uint16
	Port                 uint16
}

// FileTransferStatusInfo represents status notifications for file transfers.
type FileTransferStatusInfo struct {
	Message              string
	Status               int
	ClientFileTransferID uint16
}

// ─── 服务器 / 频道 / 客户端详细信息 ─────────────────────────

// ServerInfo holds server details from serverinfo.
type ServerInfo struct {
	Name                string // virtualserver_name
	WelcomeMessage      string // virtualserver_welcomemessage
	MaxClients          int    // virtualserver_maxclients
	ClientsOnline       int    // virtualserver_clientsonline
	ChannelsOnline      int    // virtualserver_channelsonline
	Uptime              int64  // virtualserver_uptime (秒)
	Version             string // virtualserver_version
	Platform            string // virtualserver_platform
	Created             int64  // virtualserver_created (unix timestamp)
	IconID              int64  // virtualserver_icon_id
	DefaultServerGroup  int    // virtualserver_default_server_group
	DefaultChannelGroup int    // virtualserver_default_channel_group
}

// ChannelDetailInfo holds detailed channel properties from channelinfo.
// 与 ChannelInfoDetailed 不同：ChannelDetailInfo 来自 channelinfo cid=X（单频道完整信息），
// ChannelInfoDetailed 来自 channellist -flags（批量列表的部分属性）。
type ChannelDetailInfo struct {
	ID               uint64
	ParentID         uint64
	Name             string
	Topic            string
	Description      string // channel_description (可能很长)
	Codec            int
	CodecQuality     int
	MaxClients       int
	MaxFamilyClients int
	NeededTalkPower  int
	IconID           int64
	IsPermanent      bool
	IsSemiPermanent  bool
	IsDefault        bool
	IsPassword       bool
	Order            uint64
	BannerGfxURL     string // channel_banner_gfx_url
}

// ClientDetailInfo holds detailed client properties from clientinfo clid=X.
type ClientDetailInfo struct {
	ID               uint16 // clid
	Nickname         string
	UID              string // client_unique_identifier
	ChannelID        uint64
	Type             int
	ServerGroups     []string
	Away             bool   // client_away
	AwayMessage      string // client_away_message
	InputMuted       bool   // client_input_muted
	OutputMuted      bool   // client_output_muted
	Platform         string // client_platform
	Version          string // client_version
	IP               string // connection_client_ip
	Created          int64  // client_created (unix timestamp)
	LastConnected    int64  // client_lastconnected
	TotalConnections int    // client_totalconnections
	Description      string // client_description
	IconID           int64  // client_icon_id
}

// DBClient holds one row from clientdblist.
type DBClient struct {
	DBID             uint64 // cldbid
	UID              string // client_unique_identifier
	Nickname         string // client_nickname
	Created          int64  // client_created (unix timestamp)
	LastConnected    int64  // client_lastconnected
	TotalConnections int    // client_totalconnections
	Description      string // client_description
}

// ─── 管理（Ban / 频道管理 / 文件列表）───────────────────────

// BanEntry holds one row from banlist.
type BanEntry struct {
	BanID       int64  // banid
	IP          string // ip (可能为空或部分掩码)
	Name        string // name
	UID         string // uid
	Created     int64  // created (unix timestamp)
	InvokerName string // invokername
	InvokerUID  string // invokeruid
	Reason      string // reason
	Enforcement bool   // enforcements
}

// FileEntry holds one row from ftgetfilelist.
type FileEntry struct {
	Name     string // name
	Size     uint64 // size (字节, 目录为 0)
	DateTime int64  // datetime (unix timestamp)
	IsFile   bool   // is_file (false = 目录)
}

// TokenEntry holds one row from tokenlist.
type TokenEntry struct {
	Token       string // token
	TokenType   int    // token_type (0=服务器组, 1=频道组)
	TokenID1    int64  // token_id1 (group ID)
	TokenID2    int64  // token_id2 (channel ID, 仅 token_type=1)
	Created     int64  // token_created
	Description string // token_description
}

// ComplaintEntry holds one row from complainlist.
type ComplaintEntry struct {
	FromDBID  uint64 // fcldbid
	ToDBID    uint64 // tcldbid
	Message   string // message
	Timestamp int64  // timestamp (unix timestamp)
}
