identityadoptiondecision.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "entgo.io/ent"
  8. "entgo.io/ent/dialect/sql"
  9. "github.com/Wei-Shaw/sub2api/ent/authidentity"
  10. "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
  11. "github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
  12. )
  13. // IdentityAdoptionDecision is the model entity for the IdentityAdoptionDecision schema.
  14. type IdentityAdoptionDecision struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID int64 `json:"id,omitempty"`
  18. // CreatedAt holds the value of the "created_at" field.
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // UpdatedAt holds the value of the "updated_at" field.
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // PendingAuthSessionID holds the value of the "pending_auth_session_id" field.
  23. PendingAuthSessionID int64 `json:"pending_auth_session_id,omitempty"`
  24. // IdentityID holds the value of the "identity_id" field.
  25. IdentityID *int64 `json:"identity_id,omitempty"`
  26. // AdoptDisplayName holds the value of the "adopt_display_name" field.
  27. AdoptDisplayName bool `json:"adopt_display_name,omitempty"`
  28. // AdoptAvatar holds the value of the "adopt_avatar" field.
  29. AdoptAvatar bool `json:"adopt_avatar,omitempty"`
  30. // DecidedAt holds the value of the "decided_at" field.
  31. DecidedAt time.Time `json:"decided_at,omitempty"`
  32. // Edges holds the relations/edges for other nodes in the graph.
  33. // The values are being populated by the IdentityAdoptionDecisionQuery when eager-loading is set.
  34. Edges IdentityAdoptionDecisionEdges `json:"edges"`
  35. selectValues sql.SelectValues
  36. }
  37. // IdentityAdoptionDecisionEdges holds the relations/edges for other nodes in the graph.
  38. type IdentityAdoptionDecisionEdges struct {
  39. // PendingAuthSession holds the value of the pending_auth_session edge.
  40. PendingAuthSession *PendingAuthSession `json:"pending_auth_session,omitempty"`
  41. // Identity holds the value of the identity edge.
  42. Identity *AuthIdentity `json:"identity,omitempty"`
  43. // loadedTypes holds the information for reporting if a
  44. // type was loaded (or requested) in eager-loading or not.
  45. loadedTypes [2]bool
  46. }
  47. // PendingAuthSessionOrErr returns the PendingAuthSession value or an error if the edge
  48. // was not loaded in eager-loading, or loaded but was not found.
  49. func (e IdentityAdoptionDecisionEdges) PendingAuthSessionOrErr() (*PendingAuthSession, error) {
  50. if e.PendingAuthSession != nil {
  51. return e.PendingAuthSession, nil
  52. } else if e.loadedTypes[0] {
  53. return nil, &NotFoundError{label: pendingauthsession.Label}
  54. }
  55. return nil, &NotLoadedError{edge: "pending_auth_session"}
  56. }
  57. // IdentityOrErr returns the Identity value or an error if the edge
  58. // was not loaded in eager-loading, or loaded but was not found.
  59. func (e IdentityAdoptionDecisionEdges) IdentityOrErr() (*AuthIdentity, error) {
  60. if e.Identity != nil {
  61. return e.Identity, nil
  62. } else if e.loadedTypes[1] {
  63. return nil, &NotFoundError{label: authidentity.Label}
  64. }
  65. return nil, &NotLoadedError{edge: "identity"}
  66. }
  67. // scanValues returns the types for scanning values from sql.Rows.
  68. func (*IdentityAdoptionDecision) scanValues(columns []string) ([]any, error) {
  69. values := make([]any, len(columns))
  70. for i := range columns {
  71. switch columns[i] {
  72. case identityadoptiondecision.FieldAdoptDisplayName, identityadoptiondecision.FieldAdoptAvatar:
  73. values[i] = new(sql.NullBool)
  74. case identityadoptiondecision.FieldID, identityadoptiondecision.FieldPendingAuthSessionID, identityadoptiondecision.FieldIdentityID:
  75. values[i] = new(sql.NullInt64)
  76. case identityadoptiondecision.FieldCreatedAt, identityadoptiondecision.FieldUpdatedAt, identityadoptiondecision.FieldDecidedAt:
  77. values[i] = new(sql.NullTime)
  78. default:
  79. values[i] = new(sql.UnknownType)
  80. }
  81. }
  82. return values, nil
  83. }
  84. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  85. // to the IdentityAdoptionDecision fields.
  86. func (_m *IdentityAdoptionDecision) assignValues(columns []string, values []any) error {
  87. if m, n := len(values), len(columns); m < n {
  88. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  89. }
  90. for i := range columns {
  91. switch columns[i] {
  92. case identityadoptiondecision.FieldID:
  93. value, ok := values[i].(*sql.NullInt64)
  94. if !ok {
  95. return fmt.Errorf("unexpected type %T for field id", value)
  96. }
  97. _m.ID = int64(value.Int64)
  98. case identityadoptiondecision.FieldCreatedAt:
  99. if value, ok := values[i].(*sql.NullTime); !ok {
  100. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  101. } else if value.Valid {
  102. _m.CreatedAt = value.Time
  103. }
  104. case identityadoptiondecision.FieldUpdatedAt:
  105. if value, ok := values[i].(*sql.NullTime); !ok {
  106. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  107. } else if value.Valid {
  108. _m.UpdatedAt = value.Time
  109. }
  110. case identityadoptiondecision.FieldPendingAuthSessionID:
  111. if value, ok := values[i].(*sql.NullInt64); !ok {
  112. return fmt.Errorf("unexpected type %T for field pending_auth_session_id", values[i])
  113. } else if value.Valid {
  114. _m.PendingAuthSessionID = value.Int64
  115. }
  116. case identityadoptiondecision.FieldIdentityID:
  117. if value, ok := values[i].(*sql.NullInt64); !ok {
  118. return fmt.Errorf("unexpected type %T for field identity_id", values[i])
  119. } else if value.Valid {
  120. _m.IdentityID = new(int64)
  121. *_m.IdentityID = value.Int64
  122. }
  123. case identityadoptiondecision.FieldAdoptDisplayName:
  124. if value, ok := values[i].(*sql.NullBool); !ok {
  125. return fmt.Errorf("unexpected type %T for field adopt_display_name", values[i])
  126. } else if value.Valid {
  127. _m.AdoptDisplayName = value.Bool
  128. }
  129. case identityadoptiondecision.FieldAdoptAvatar:
  130. if value, ok := values[i].(*sql.NullBool); !ok {
  131. return fmt.Errorf("unexpected type %T for field adopt_avatar", values[i])
  132. } else if value.Valid {
  133. _m.AdoptAvatar = value.Bool
  134. }
  135. case identityadoptiondecision.FieldDecidedAt:
  136. if value, ok := values[i].(*sql.NullTime); !ok {
  137. return fmt.Errorf("unexpected type %T for field decided_at", values[i])
  138. } else if value.Valid {
  139. _m.DecidedAt = value.Time
  140. }
  141. default:
  142. _m.selectValues.Set(columns[i], values[i])
  143. }
  144. }
  145. return nil
  146. }
  147. // Value returns the ent.Value that was dynamically selected and assigned to the IdentityAdoptionDecision.
  148. // This includes values selected through modifiers, order, etc.
  149. func (_m *IdentityAdoptionDecision) Value(name string) (ent.Value, error) {
  150. return _m.selectValues.Get(name)
  151. }
  152. // QueryPendingAuthSession queries the "pending_auth_session" edge of the IdentityAdoptionDecision entity.
  153. func (_m *IdentityAdoptionDecision) QueryPendingAuthSession() *PendingAuthSessionQuery {
  154. return NewIdentityAdoptionDecisionClient(_m.config).QueryPendingAuthSession(_m)
  155. }
  156. // QueryIdentity queries the "identity" edge of the IdentityAdoptionDecision entity.
  157. func (_m *IdentityAdoptionDecision) QueryIdentity() *AuthIdentityQuery {
  158. return NewIdentityAdoptionDecisionClient(_m.config).QueryIdentity(_m)
  159. }
  160. // Update returns a builder for updating this IdentityAdoptionDecision.
  161. // Note that you need to call IdentityAdoptionDecision.Unwrap() before calling this method if this IdentityAdoptionDecision
  162. // was returned from a transaction, and the transaction was committed or rolled back.
  163. func (_m *IdentityAdoptionDecision) Update() *IdentityAdoptionDecisionUpdateOne {
  164. return NewIdentityAdoptionDecisionClient(_m.config).UpdateOne(_m)
  165. }
  166. // Unwrap unwraps the IdentityAdoptionDecision entity that was returned from a transaction after it was closed,
  167. // so that all future queries will be executed through the driver which created the transaction.
  168. func (_m *IdentityAdoptionDecision) Unwrap() *IdentityAdoptionDecision {
  169. _tx, ok := _m.config.driver.(*txDriver)
  170. if !ok {
  171. panic("ent: IdentityAdoptionDecision is not a transactional entity")
  172. }
  173. _m.config.driver = _tx.drv
  174. return _m
  175. }
  176. // String implements the fmt.Stringer.
  177. func (_m *IdentityAdoptionDecision) String() string {
  178. var builder strings.Builder
  179. builder.WriteString("IdentityAdoptionDecision(")
  180. builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
  181. builder.WriteString("created_at=")
  182. builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
  183. builder.WriteString(", ")
  184. builder.WriteString("updated_at=")
  185. builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
  186. builder.WriteString(", ")
  187. builder.WriteString("pending_auth_session_id=")
  188. builder.WriteString(fmt.Sprintf("%v", _m.PendingAuthSessionID))
  189. builder.WriteString(", ")
  190. if v := _m.IdentityID; v != nil {
  191. builder.WriteString("identity_id=")
  192. builder.WriteString(fmt.Sprintf("%v", *v))
  193. }
  194. builder.WriteString(", ")
  195. builder.WriteString("adopt_display_name=")
  196. builder.WriteString(fmt.Sprintf("%v", _m.AdoptDisplayName))
  197. builder.WriteString(", ")
  198. builder.WriteString("adopt_avatar=")
  199. builder.WriteString(fmt.Sprintf("%v", _m.AdoptAvatar))
  200. builder.WriteString(", ")
  201. builder.WriteString("decided_at=")
  202. builder.WriteString(_m.DecidedAt.Format(time.ANSIC))
  203. builder.WriteByte(')')
  204. return builder.String()
  205. }
  206. // IdentityAdoptionDecisions is a parsable slice of IdentityAdoptionDecision.
  207. type IdentityAdoptionDecisions []*IdentityAdoptionDecision