package models

import "time"

// WorkspaceRole controls what a member can do inside a workspace.
type WorkspaceRole string

const (
	WorkspaceRoleOwner  WorkspaceRole = "owner"
	WorkspaceRoleAdmin  WorkspaceRole = "admin"
	WorkspaceRoleMember WorkspaceRole = "member"
)

// Workspace is a named collaborative namespace that can own repositories.
// Its handle must be globally unique across all usernames and workspace handles
// so that /{owner}/{repo} URLs remain unambiguous.
type Workspace struct {
	ID          int64     `xorm:"'id' pk autoincr"                          json:"id"`
	Handle      string    `xorm:"'handle' unique notnull varchar(64)"        json:"handle"`
	DisplayName string    `xorm:"'display_name' varchar(255)"               json:"displayName"`
	Description string    `xorm:"'description' text"                        json:"description"`
	AvatarURL   string    `xorm:"'avatar_url' varchar(500)"                 json:"avatarUrl"`
	CreatedBy   int64     `xorm:"'created_by' notnull"                      json:"createdBy"`
	CreatedAt   time.Time `xorm:"'created_at' created"                      json:"createdAt"`
	UpdatedAt   time.Time `xorm:"'updated_at' updated"                      json:"updatedAt"`
}

// WorkspaceMember links a User to a Workspace with a role.
type WorkspaceMember struct {
	ID          int64         `xorm:"'id' pk autoincr"              json:"id"`
	WorkspaceID int64         `xorm:"'workspace_id' notnull index"  json:"workspaceId"`
	UserID      int64         `xorm:"'user_id' notnull index"       json:"userId"`
	Username    string        `xorm:"'username' varchar(64)"        json:"username"`
	Role        WorkspaceRole `xorm:"'role' varchar(20)"            json:"role"`
	AddedAt     time.Time     `xorm:"'added_at' created"            json:"addedAt"`
}
