package model

import (
	"time"

	"gorm.io/gorm"
)

// WeComApplication 企业微信自建应用及加密连接凭据。
type WeComApplication struct {
	gorm.Model
	CorpID                   string     `gorm:"column:corp_id;type:varchar(64);not null;uniqueIndex:uq_wecom_application_identity,priority:1,where:deleted_at IS NULL" json:"corp_id"`
	AgentID                  int64      `gorm:"column:agent_id;type:bigint;not null;uniqueIndex:uq_wecom_application_identity,priority:2,where:deleted_at IS NULL" json:"agent_id"`
	Name                     string     `gorm:"column:name;type:varchar(100);not null" json:"name"`
	SecretCiphertext         []byte     `gorm:"column:secret_ciphertext;type:bytea;not null" json:"-"`
	CallbackTokenCiphertext  []byte     `gorm:"column:callback_token_ciphertext;type:bytea;not null" json:"-"`
	EncodingAESKeyCiphertext []byte     `gorm:"column:encoding_aes_key_ciphertext;type:bytea;not null" json:"-"`
	DefaultCreatorUserID     string     `gorm:"column:default_creator_userid;type:varchar(64);not null;default:''" json:"default_creator_userid"`
	DefaultCreatorName       string     `gorm:"column:default_creator_name;type:varchar(100);not null;default:''" json:"default_creator_name"`
	Status                   int        `gorm:"column:status;type:int;not null;default:1" json:"status"`
	CreatedBy                uint       `gorm:"column:created_by;not null" json:"created_by"`
	UpdatedBy                uint       `gorm:"column:updated_by;not null" json:"updated_by"`
	LastConnectedAt          *time.Time `gorm:"column:last_connected_at;type:timestamptz" json:"last_connected_at,omitempty"`
}

// TableName 指定企业微信应用表名。
func (WeComApplication) TableName() string {
	return "tb_wecom_application"
}
