<commit_before>package types

import "errors"

type RoomDescription struct {
	Visibility Visibility `json:"visibility"`
	Alias      *string    `json:"room_alias_name"`
	Name       *string    `json:"name"`
	Topic      *string    `json:"topic"`
	Invited    []UserId   `json:"invite"`
}

type Visibility int

const (
	VisibilityPrivate Visibility = 0
	VisibilityPublic             = 1
)

type JoinRule int

const (
	JoinRuleNone    JoinRule = 0
	JoinRulePublic           = 1
	JoinRuleInvite           = 2
	JoinRulePrivate          = 3
	JoinRuleKnock            = 4
)

type Membership int

const (
	MembershipNone     Membership = 0
	MembershipInvited             = 1
	MembershipMember              = 2
	MembershipKnocking            = 3
	MembershipLeaving             = 4
	MembershipBanned              = 5
)

func (v Visibility) ToJoinRule() JoinRule {
	if v == VisibilityPublic {
		return JoinRulePublic
	} else {
		return JoinRuleInvite
	}
}

func (v *Visibility) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "\"private\"":
		*v = VisibilityPrivate
		return nil
	case "\"public\"":
		*v = VisibilityPublic
		return nil
	}
	return errors.New("invalid visibility identifier: '" + str + "'")
}

func (v Visibility) MarshalJSON() ([]byte, error) {
	switch v {
	case VisibilityPrivate:
		return []byte("\"private\""), nil
	case VisibilityPublic:
		return []byte("\"public\""), nil
	}
	return nil, errors.New("invalid visibility value: '" + string(v) + "'")
}

func (v *JoinRule) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "null":
		*v = JoinRuleNone
		return nil
	case "\"public\"":
		*v = JoinRulePublic
		return nil
	case "\"invite\"":
		*v = JoinRuleInvite
		return nil
	case "\"private\"":
		*v = JoinRulePrivate
		return nil
	case "\"knock\"":
		*v = JoinRuleKnock
		return nil
	}
	return errors.New("invalid join rule identifier: '" + str + "'")
}

func (v JoinRule) MarshalJSON() ([]byte, error) {
	switch v {
	case JoinRuleNone:
		return []byte("null"), nil
	case JoinRulePublic:
		return []byte("\"public\""), nil
	case JoinRuleInvite:
		return []byte("\"invite\""), nil
	case JoinRulePrivate:
		return []byte("\"private\""), nil
	case JoinRuleKnock:
		return []byte("\"knock\""), nil
	}
	return nil, errors.New("invalid join rule value: '" + string(v) + "'")
}

func (v *Membership) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "null":
		*v = MembershipNone
		return nil
	case "\"invite\"":
		*v = MembershipInvited
		return nil
	case "\"join\"":
		*v = MembershipMember
		return nil
	case "\"knock\"":
		*v = MembershipKnocking
		return nil
	case "\"leave\"":
		*v = MembershipLeaving
		return nil
	case "\"ban\"":
		*v = MembershipBanned
		return nil
	}
	return errors.New("invalid membership identifier: '" + str + "'")
}

func (v Membership) MarshalJSON() ([]byte, error) {
	switch v {
	case MembershipNone:
		return []byte("null"), nil
	case MembershipInvited:
		return []byte("\"invite\""), nil
	case MembershipMember:
		return []byte("\"join\""), nil
	case MembershipKnocking:
		return []byte("\"knock\""), nil
	case MembershipLeaving:
		return []byte("\"leave\""), nil
	case MembershipBanned:
		return []byte("\"ban\""), nil
	}
	return nil, errors.New("invalid membership value: '" + string(v) + "'")
}<commit_msg>types/rooms: added String methods for JoinRule and Membership<commit_after>package types

import (
	"errors"
	"fmt"
)

type RoomDescription struct {
	Visibility Visibility `json:"visibility"`
	Alias      *string    `json:"room_alias_name"`
	Name       *string    `json:"name"`
	Topic      *string    `json:"topic"`
	Invited    []UserId   `json:"invite"`
}

type Visibility int

const (
	VisibilityPrivate Visibility = 0
	VisibilityPublic             = 1
)

type JoinRule int

const (
	JoinRuleNone    JoinRule = 0
	JoinRulePublic           = 1
	JoinRuleInvite           = 2
	JoinRulePrivate          = 3
	JoinRuleKnock            = 4
)

type Membership int

const (
	MembershipNone     Membership = 0
	MembershipInvited             = 1
	MembershipMember              = 2
	MembershipKnocking            = 3
	MembershipLeaving             = 4
	MembershipBanned              = 5
)

func (v Visibility) ToJoinRule() JoinRule {
	if v == VisibilityPublic {
		return JoinRulePublic
	} else {
		return JoinRuleInvite
	}
}

func (v *Visibility) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "\"private\"":
		*v = VisibilityPrivate
		return nil
	case "\"public\"":
		*v = VisibilityPublic
		return nil
	}
	return errors.New("invalid visibility identifier: '" + str + "'")
}

func (v Visibility) MarshalJSON() ([]byte, error) {
	switch v {
	case VisibilityPrivate:
		return []byte("\"private\""), nil
	case VisibilityPublic:
		return []byte("\"public\""), nil
	}
	return nil, errors.New("invalid visibility value: '" + string(v) + "'")
}

func (j *JoinRule) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "null":
		*j = JoinRuleNone
		return nil
	case "\"public\"":
		*j = JoinRulePublic
		return nil
	case "\"invite\"":
		*j = JoinRuleInvite
		return nil
	case "\"private\"":
		*j = JoinRulePrivate
		return nil
	case "\"knock\"":
		*j = JoinRuleKnock
		return nil
	}
	return errors.New("invalid join rule identifier: '" + str + "'")
}

func (j JoinRule) String() string {
	switch j {
	case JoinRulePublic:
		return "public"
	case JoinRuleInvite:
		return "invite"
	case JoinRulePrivate:
		return "private"
	case JoinRuleKnock:
		return "knock"
	}
	return ""
}

func (j JoinRule) MarshalJSON() ([]byte, error) {
	str := j.String()
	if str == "" {
		return []byte("null"), nil
	}
	return []byte(fmt.Sprintf("\"%s\"", str)), nil
}

func (m *Membership) UnmarshalJSON(bytes []byte) error {
	str := string(bytes)
	switch str {
	case "null":
		*m = MembershipNone
		return nil
	case "\"invite\"":
		*m = MembershipInvited
		return nil
	case "\"join\"":
		*m = MembershipMember
		return nil
	case "\"knock\"":
		*m = MembershipKnocking
		return nil
	case "\"leave\"":
		*m = MembershipLeaving
		return nil
	case "\"ban\"":
		*m = MembershipBanned
		return nil
	}
	return errors.New("invalid membership identifier: '" + str + "'")
}

func (m Membership) String() string {
	switch m {
	case MembershipInvited:
		return "invite"
	case MembershipMember:
		return "join"
	case MembershipKnocking:
		return "knock"
	case MembershipLeaving:
		return "leave"
	case MembershipBanned:
		return "ban"
	}
	return ""
}

func (m Membership) MarshalJSON() ([]byte, error) {
	str := m.String()
	if str == "" {
		return []byte("null"), nil
	}
	return []byte(fmt.Sprintf("\"%s\"", str)), nil
}
{'fraction_non_alphanumeric': 0.1418045112781955, 'fraction_numerical': 0.003909774436090226, 'mean_word_length': 3.296511627906977, 'pattern_counts': {'":': 26, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5646799', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2233, 'n_words': 626}