// Code generated by ent, DO NOT EDIT.

package publisherpermission

import (
	"fmt"
	"registry-backend/ent/schema"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
)

const (
	// Label holds the string label denoting the publisherpermission type in the database.
	Label = "publisher_permission"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldPermission holds the string denoting the permission field in the database.
	FieldPermission = "permission"
	// FieldUserID holds the string denoting the user_id field in the database.
	FieldUserID = "user_id"
	// FieldPublisherID holds the string denoting the publisher_id field in the database.
	FieldPublisherID = "publisher_id"
	// EdgeUser holds the string denoting the user edge name in mutations.
	EdgeUser = "user"
	// EdgePublisher holds the string denoting the publisher edge name in mutations.
	EdgePublisher = "publisher"
	// Table holds the table name of the publisherpermission in the database.
	Table = "publisher_permissions"
	// UserTable is the table that holds the user relation/edge.
	UserTable = "publisher_permissions"
	// UserInverseTable is the table name for the User entity.
	// It exists in this package in order to avoid circular dependency with the "user" package.
	UserInverseTable = "users"
	// UserColumn is the table column denoting the user relation/edge.
	UserColumn = "user_id"
	// PublisherTable is the table that holds the publisher relation/edge.
	PublisherTable = "publisher_permissions"
	// PublisherInverseTable is the table name for the Publisher entity.
	// It exists in this package in order to avoid circular dependency with the "publisher" package.
	PublisherInverseTable = "publishers"
	// PublisherColumn is the table column denoting the publisher relation/edge.
	PublisherColumn = "publisher_id"
)

// Columns holds all SQL columns for publisherpermission fields.
var Columns = []string{
	FieldID,
	FieldPermission,
	FieldUserID,
	FieldPublisherID,
}

// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
	for i := range Columns {
		if column == Columns[i] {
			return true
		}
	}
	return false
}

// PermissionValidator is a validator for the "permission" field enum values. It is called by the builders before save.
func PermissionValidator(pe schema.PublisherPermissionType) error {
	switch pe {
	case "owner", "member":
		return nil
	default:
		return fmt.Errorf("publisherpermission: invalid enum value for permission field: %q", pe)
	}
}

// OrderOption defines the ordering options for the PublisherPermission queries.
type OrderOption func(*sql.Selector)

// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldID, opts...).ToFunc()
}

// ByPermission orders the results by the permission field.
func ByPermission(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldPermission, opts...).ToFunc()
}

// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldUserID, opts...).ToFunc()
}

// ByPublisherID orders the results by the publisher_id field.
func ByPublisherID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldPublisherID, opts...).ToFunc()
}

// ByUserField orders the results by user field.
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
	}
}

// ByPublisherField orders the results by publisher field.
func ByPublisherField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newPublisherStep(), sql.OrderByField(field, opts...))
	}
}
func newUserStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(UserInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
	)
}
func newPublisherStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(PublisherInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, true, PublisherTable, PublisherColumn),
	)
}
