// Code generated by ent, DO NOT EDIT.

package orginvitation

import (
	"fmt"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/authz"
	"github.com/chainloop-dev/chainloop/app/controlplane/pkg/biz"
	"github.com/google/uuid"
)

const (
	// Label holds the string label denoting the orginvitation type in the database.
	Label = "org_invitation"
	// FieldID holds the string denoting the id field in the database.
	FieldID = "id"
	// FieldReceiverEmail holds the string denoting the receiver_email field in the database.
	FieldReceiverEmail = "receiver_email"
	// FieldStatus holds the string denoting the status field in the database.
	FieldStatus = "status"
	// FieldCreatedAt holds the string denoting the created_at field in the database.
	FieldCreatedAt = "created_at"
	// FieldDeletedAt holds the string denoting the deleted_at field in the database.
	FieldDeletedAt = "deleted_at"
	// FieldOrganizationID holds the string denoting the organization_id field in the database.
	FieldOrganizationID = "organization_id"
	// FieldSenderID holds the string denoting the sender_id field in the database.
	FieldSenderID = "sender_id"
	// FieldRole holds the string denoting the role field in the database.
	FieldRole = "role"
	// FieldContext holds the string denoting the context field in the database.
	FieldContext = "context"
	// EdgeOrganization holds the string denoting the organization edge name in mutations.
	EdgeOrganization = "organization"
	// EdgeSender holds the string denoting the sender edge name in mutations.
	EdgeSender = "sender"
	// Table holds the table name of the orginvitation in the database.
	Table = "org_invitations"
	// OrganizationTable is the table that holds the organization relation/edge.
	OrganizationTable = "org_invitations"
	// OrganizationInverseTable is the table name for the Organization entity.
	// It exists in this package in order to avoid circular dependency with the "organization" package.
	OrganizationInverseTable = "organizations"
	// OrganizationColumn is the table column denoting the organization relation/edge.
	OrganizationColumn = "organization_id"
	// SenderTable is the table that holds the sender relation/edge.
	SenderTable = "org_invitations"
	// SenderInverseTable is the table name for the User entity.
	// It exists in this package in order to avoid circular dependency with the "user" package.
	SenderInverseTable = "users"
	// SenderColumn is the table column denoting the sender relation/edge.
	SenderColumn = "sender_id"
)

// Columns holds all SQL columns for orginvitation fields.
var Columns = []string{
	FieldID,
	FieldReceiverEmail,
	FieldStatus,
	FieldCreatedAt,
	FieldDeletedAt,
	FieldOrganizationID,
	FieldSenderID,
	FieldRole,
	FieldContext,
}

// 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
}

var (
	// DefaultCreatedAt holds the default value on creation for the "created_at" field.
	DefaultCreatedAt func() time.Time
	// DefaultID holds the default value on creation for the "id" field.
	DefaultID func() uuid.UUID
)

const DefaultStatus biz.OrgInvitationStatus = "pending"

// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
func StatusValidator(s biz.OrgInvitationStatus) error {
	switch s {
	case "accepted", "pending":
		return nil
	default:
		return fmt.Errorf("orginvitation: invalid enum value for status field: %q", s)
	}
}

// RoleValidator is a validator for the "role" field enum values. It is called by the builders before save.
func RoleValidator(r authz.Role) error {
	switch r {
	case "role:instance:admin", "role:org:owner", "role:org:admin", "role:org:viewer", "role:org:member", "role:org:contributor", "role:project:admin", "role:project:viewer", "role:group:maintainer", "role:product:admin", "role:product:viewer":
		return nil
	default:
		return fmt.Errorf("orginvitation: invalid enum value for role field: %q", r)
	}
}

// OrderOption defines the ordering options for the OrgInvitation 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()
}

// ByReceiverEmail orders the results by the receiver_email field.
func ByReceiverEmail(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldReceiverEmail, opts...).ToFunc()
}

// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldStatus, opts...).ToFunc()
}

// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}

// ByDeletedAt orders the results by the deleted_at field.
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
}

// ByOrganizationID orders the results by the organization_id field.
func ByOrganizationID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldOrganizationID, opts...).ToFunc()
}

// BySenderID orders the results by the sender_id field.
func BySenderID(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldSenderID, opts...).ToFunc()
}

// ByRole orders the results by the role field.
func ByRole(opts ...sql.OrderTermOption) OrderOption {
	return sql.OrderByField(FieldRole, opts...).ToFunc()
}

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

// BySenderField orders the results by sender field.
func BySenderField(field string, opts ...sql.OrderTermOption) OrderOption {
	return func(s *sql.Selector) {
		sqlgraph.OrderByNeighborTerms(s, newSenderStep(), sql.OrderByField(field, opts...))
	}
}
func newOrganizationStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(OrganizationInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, OrganizationTable, OrganizationColumn),
	)
}
func newSenderStep() *sqlgraph.Step {
	return sqlgraph.NewStep(
		sqlgraph.From(Table, FieldID),
		sqlgraph.To(SenderInverseTable, FieldID),
		sqlgraph.Edge(sqlgraph.M2O, false, SenderTable, SenderColumn),
	)
}
