package acl

import (
	acl "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/acl/grpc"
)

// String returns string representation of Action.
func (x Action) String() string {
	return ActionToGRPCField(x).String()
}

// FromString parses Action from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Action) FromString(s string) bool {
	g, ok := acl.Action_value[s]
	if ok {
		*x = ActionFromGRPCField(acl.Action(g))
	}

	return ok
}

// String returns string representation of Role.
func (x Role) String() string {
	return RoleToGRPCField(x).String()
}

// FromString parses Role from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Role) FromString(s string) bool {
	g, ok := acl.Role_value[s]

	if ok {
		*x = RoleFromGRPCField(acl.Role(g))
	}

	return ok
}

// String returns string representation of Operation.
func (x Operation) String() string {
	return OperationToGRPCField(x).String()
}

// FromString parses Operation from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *Operation) FromString(s string) bool {
	g, ok := acl.Operation_value[s]
	if ok {
		*x = OperationFromGRPCField(acl.Operation(g))
	}

	return ok
}

// String returns string representation of MatchType.
func (x MatchType) String() string {
	return MatchTypeToGRPCField(x).String()
}

// FromString parses MatchType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *MatchType) FromString(s string) bool {
	g, ok := acl.MatchType_value[s]

	if ok {
		*x = MatchTypeFromGRPCField(acl.MatchType(g))
	}

	return ok
}

// String returns string representation of HeaderType.
func (x HeaderType) String() string {
	return HeaderTypeToGRPCField(x).String()
}

// FromString parses HeaderType from a string representation.
// It is a reverse action to String().
//
// Returns true if s was parsed successfully.
func (x *HeaderType) FromString(s string) bool {
	g, ok := acl.HeaderType_value[s]

	if ok {
		*x = HeaderTypeFromGRPCField(acl.HeaderType(g))
	}

	return ok
}