package v1

import (
	"database/sql"
	"time"

	"gorm.io/gorm"
)

type WikiDoc struct {
	ID         uint64         `gorm:"primaryKey;autoIncrement:true" json:"id"`
	CreatedAt  time.Time      `gorm:"not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt  sql.NullTime   `gorm:"default:null" json:"updated_at,omitempty"`
	DeletedAt  gorm.DeletedAt `gorm:"default:null" json:"deleted_at,omitempty"`
	SpaceID    string         `gorm:"size:128;not null;default:'0'" json:"space_id"`
	ParentID   string         `gorm:"size:128;not null" json:"parent_id"`
	URL        string         `gorm:"size:256;not null" json:"url"`
	Title      string         `gorm:"size:255;not null" json:"title"`
	ObjToken   string         `gorm:"size:255;not null" json:"obj_token"`
	NodeToken  string         `gorm:"size:255;not null" json:"node_token"`
	Owner      string         `gorm:"size:64;not null" json:"owner"`
	Type       string         `gorm:"not null" json:"type"`
	Content    []byte         `json:"content"`
	Level      int            `gorm:"not null" json:"level"`
	Reason     int            `gorm:"not null" json:"reason"`
	RegID      uint64         `gorm:"not null" json:"reg_id"`
	Permission int            `json:"permission"`
}

func (WikiDoc) TableName() string {
	return "wiki_doc"
}

type WikiRegular struct {
	ID        uint64         `gorm:"primaryKey;autoIncrement:true" json:"id"`
	CreatedAt time.Time      `gorm:"not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt sql.NullTime   `gorm:"not null" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"not null" json:"deleted_at"`
	Name      string         `gorm:"size:16;not null;default:'0'" json:"name"`
	Level     int            `json:"level"`
	GroupID   int            `gorm:"not null" json:"group_id"`
	GroupName string         `gorm:"size:32;not null" json:"group_name"`
	Attribute int            `gorm:"not null" json:"attribute"` // '1' represents regex and '2' represents keyword
	Enable    int            `gorm:"not null" json:"enable"`
	Remark    string         `gorm:"size:32;not null" json:"remark"`
	Content   string         `gorm:"type:text;not null" json:"content"`
}

func (WikiRegular) TableName() string {
	return "wiki_regular"
}

type WikiSpace struct {
	ID          uint64         `gorm:"primaryKey;autoIncrement:true" json:"id"`
	CreatedAt   time.Time      `gorm:"not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt   sql.NullTime   `gorm:"default:null" json:"updated_at,omitempty"`
	DeletedAt   gorm.DeletedAt `gorm:"default:null" json:"deleted_at,omitempty"`
	SpaceID     string         `gorm:"size:128;not null;default:'0'" json:"space_id"`
	Name        string         `gorm:"size:64;not null" json:"name"`
	Description string         `gorm:"size:128;not null" json:"description"`
}

func (WikiSpace) TableName() string {
	return "wiki_space"
}

type WikiApproval struct {
	ID               uint64         `gorm:"primaryKey;autoIncrement:true" json:"id"`
	CreatedAt        time.Time      `gorm:"not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt        sql.NullTime   `gorm:"default:null" json:"updated_at,omitempty"`
	DeletedAt        gorm.DeletedAt `gorm:"default:null" json:"deleted_at,omitempty"`
	Owner            string         `gorm:"size:128;not null" json:"owner"`
	ApprovalInstance string         `gorm:"size:256;not null" json:"approval_instance"`
	Status           int            `gorm:"not null" json:"status"`
}

func (WikiApproval) TableName() string {
	return "wiki_approval"
}

type WikiPermission struct {
	ID                       uint64         `gorm:"primaryKey;autoIncrement:true" json:"id"`
	CreatedAt                time.Time      `gorm:"not null;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt                sql.NullTime   `gorm:"default:null" json:"updated_at,omitempty"`
	DeletedAt                gorm.DeletedAt `gorm:"default:null" json:"deleted_at,omitempty"`
	Level                    int            `json:"level"`
	ExternalAccessEntity     string         `json:"external_access_entity"`
	SecurityEntity           string         `json:"security_entity"`
	CommentEntity            string         `json:"comment_entity"`
	ShareEntity              string         `json:"share_entity"`
	ManageCollaboratorEntity string         `json:"manage_collaborator_entity"`
	LinkShareEntity          string         `json:"link_share_entity"`
	CopyEntity               string         `json:"copy_entity"`
	LockSwitch               int            `json:"lock_switch"`
}

func (WikiPermission) TableName() string {
	return "wiki_permission"
}
