package types import ( "errors" "time" ) const MaxAccounts = 20 var ErrMaxAccountsReached = errors.New("maximum number of linked accounts reached") type AccountInfo struct { Did string `json:"did"` SessionId string `json:"session_id"` AddedAt int64 `json:"added_at"` } type AccountRegistry struct { Accounts []AccountInfo `json:"accounts"` } func (r *AccountRegistry) AddAccount(did, sessionId string) error { for i, acc := range r.Accounts { if acc.Did == did { r.Accounts[i].SessionId = sessionId return nil } } if len(r.Accounts) >= MaxAccounts { return ErrMaxAccountsReached } r.Accounts = append(r.Accounts, AccountInfo{ Did: did, SessionId: sessionId, AddedAt: time.Now().Unix(), }) return nil } func (r *AccountRegistry) RemoveAccount(did string) { filtered := make([]AccountInfo, 0, len(r.Accounts)) for _, acc := range r.Accounts { if acc.Did != did { filtered = append(filtered, acc) } } r.Accounts = filtered } func (r *AccountRegistry) FindAccount(did string) *AccountInfo { for i := range r.Accounts { if r.Accounts[i].Did == did { return &r.Accounts[i] } } return nil } func (r *AccountRegistry) OtherAccounts(activeDid string) []AccountInfo { result := make([]AccountInfo, 0, len(r.Accounts)) for _, acc := range r.Accounts { if acc.Did != activeDid { result = append(result, acc) } } return result } type MultiAccountUser struct { Active *User Accounts []AccountInfo } func (m *MultiAccountUser) Did() string { if m.Active == nil { return "" } return m.Active.Did } func (m *MultiAccountUser) Pds() string { if m.Active == nil { return "" } return m.Active.Pds } type User struct { Did string Pds string } type AuthReturnInfo struct { ReturnURL string AddAccount bool }