github.com/crowdsecurity/crowdsec@v1.6.1/pkg/database/ent/decision.go (about)

     1  // Code generated by ent, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"entgo.io/ent"
    11  	"entgo.io/ent/dialect/sql"
    12  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/alert"
    13  	"github.com/crowdsecurity/crowdsec/pkg/database/ent/decision"
    14  )
    15  
    16  // Decision is the model entity for the Decision schema.
    17  type Decision struct {
    18  	config `json:"-"`
    19  	// ID of the ent.
    20  	ID int `json:"id,omitempty"`
    21  	// CreatedAt holds the value of the "created_at" field.
    22  	CreatedAt *time.Time `json:"created_at,omitempty"`
    23  	// UpdatedAt holds the value of the "updated_at" field.
    24  	UpdatedAt *time.Time `json:"updated_at,omitempty"`
    25  	// Until holds the value of the "until" field.
    26  	Until *time.Time `json:"until,omitempty"`
    27  	// Scenario holds the value of the "scenario" field.
    28  	Scenario string `json:"scenario,omitempty"`
    29  	// Type holds the value of the "type" field.
    30  	Type string `json:"type,omitempty"`
    31  	// StartIP holds the value of the "start_ip" field.
    32  	StartIP int64 `json:"start_ip,omitempty"`
    33  	// EndIP holds the value of the "end_ip" field.
    34  	EndIP int64 `json:"end_ip,omitempty"`
    35  	// StartSuffix holds the value of the "start_suffix" field.
    36  	StartSuffix int64 `json:"start_suffix,omitempty"`
    37  	// EndSuffix holds the value of the "end_suffix" field.
    38  	EndSuffix int64 `json:"end_suffix,omitempty"`
    39  	// IPSize holds the value of the "ip_size" field.
    40  	IPSize int64 `json:"ip_size,omitempty"`
    41  	// Scope holds the value of the "scope" field.
    42  	Scope string `json:"scope,omitempty"`
    43  	// Value holds the value of the "value" field.
    44  	Value string `json:"value,omitempty"`
    45  	// Origin holds the value of the "origin" field.
    46  	Origin string `json:"origin,omitempty"`
    47  	// Simulated holds the value of the "simulated" field.
    48  	Simulated bool `json:"simulated,omitempty"`
    49  	// UUID holds the value of the "uuid" field.
    50  	UUID string `json:"uuid,omitempty"`
    51  	// AlertDecisions holds the value of the "alert_decisions" field.
    52  	AlertDecisions int `json:"alert_decisions,omitempty"`
    53  	// Edges holds the relations/edges for other nodes in the graph.
    54  	// The values are being populated by the DecisionQuery when eager-loading is set.
    55  	Edges        DecisionEdges `json:"edges"`
    56  	selectValues sql.SelectValues
    57  }
    58  
    59  // DecisionEdges holds the relations/edges for other nodes in the graph.
    60  type DecisionEdges struct {
    61  	// Owner holds the value of the owner edge.
    62  	Owner *Alert `json:"owner,omitempty"`
    63  	// loadedTypes holds the information for reporting if a
    64  	// type was loaded (or requested) in eager-loading or not.
    65  	loadedTypes [1]bool
    66  }
    67  
    68  // OwnerOrErr returns the Owner value or an error if the edge
    69  // was not loaded in eager-loading, or loaded but was not found.
    70  func (e DecisionEdges) OwnerOrErr() (*Alert, error) {
    71  	if e.loadedTypes[0] {
    72  		if e.Owner == nil {
    73  			// Edge was loaded but was not found.
    74  			return nil, &NotFoundError{label: alert.Label}
    75  		}
    76  		return e.Owner, nil
    77  	}
    78  	return nil, &NotLoadedError{edge: "owner"}
    79  }
    80  
    81  // scanValues returns the types for scanning values from sql.Rows.
    82  func (*Decision) scanValues(columns []string) ([]any, error) {
    83  	values := make([]any, len(columns))
    84  	for i := range columns {
    85  		switch columns[i] {
    86  		case decision.FieldSimulated:
    87  			values[i] = new(sql.NullBool)
    88  		case decision.FieldID, decision.FieldStartIP, decision.FieldEndIP, decision.FieldStartSuffix, decision.FieldEndSuffix, decision.FieldIPSize, decision.FieldAlertDecisions:
    89  			values[i] = new(sql.NullInt64)
    90  		case decision.FieldScenario, decision.FieldType, decision.FieldScope, decision.FieldValue, decision.FieldOrigin, decision.FieldUUID:
    91  			values[i] = new(sql.NullString)
    92  		case decision.FieldCreatedAt, decision.FieldUpdatedAt, decision.FieldUntil:
    93  			values[i] = new(sql.NullTime)
    94  		default:
    95  			values[i] = new(sql.UnknownType)
    96  		}
    97  	}
    98  	return values, nil
    99  }
   100  
   101  // assignValues assigns the values that were returned from sql.Rows (after scanning)
   102  // to the Decision fields.
   103  func (d *Decision) assignValues(columns []string, values []any) error {
   104  	if m, n := len(values), len(columns); m < n {
   105  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
   106  	}
   107  	for i := range columns {
   108  		switch columns[i] {
   109  		case decision.FieldID:
   110  			value, ok := values[i].(*sql.NullInt64)
   111  			if !ok {
   112  				return fmt.Errorf("unexpected type %T for field id", value)
   113  			}
   114  			d.ID = int(value.Int64)
   115  		case decision.FieldCreatedAt:
   116  			if value, ok := values[i].(*sql.NullTime); !ok {
   117  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
   118  			} else if value.Valid {
   119  				d.CreatedAt = new(time.Time)
   120  				*d.CreatedAt = value.Time
   121  			}
   122  		case decision.FieldUpdatedAt:
   123  			if value, ok := values[i].(*sql.NullTime); !ok {
   124  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   125  			} else if value.Valid {
   126  				d.UpdatedAt = new(time.Time)
   127  				*d.UpdatedAt = value.Time
   128  			}
   129  		case decision.FieldUntil:
   130  			if value, ok := values[i].(*sql.NullTime); !ok {
   131  				return fmt.Errorf("unexpected type %T for field until", values[i])
   132  			} else if value.Valid {
   133  				d.Until = new(time.Time)
   134  				*d.Until = value.Time
   135  			}
   136  		case decision.FieldScenario:
   137  			if value, ok := values[i].(*sql.NullString); !ok {
   138  				return fmt.Errorf("unexpected type %T for field scenario", values[i])
   139  			} else if value.Valid {
   140  				d.Scenario = value.String
   141  			}
   142  		case decision.FieldType:
   143  			if value, ok := values[i].(*sql.NullString); !ok {
   144  				return fmt.Errorf("unexpected type %T for field type", values[i])
   145  			} else if value.Valid {
   146  				d.Type = value.String
   147  			}
   148  		case decision.FieldStartIP:
   149  			if value, ok := values[i].(*sql.NullInt64); !ok {
   150  				return fmt.Errorf("unexpected type %T for field start_ip", values[i])
   151  			} else if value.Valid {
   152  				d.StartIP = value.Int64
   153  			}
   154  		case decision.FieldEndIP:
   155  			if value, ok := values[i].(*sql.NullInt64); !ok {
   156  				return fmt.Errorf("unexpected type %T for field end_ip", values[i])
   157  			} else if value.Valid {
   158  				d.EndIP = value.Int64
   159  			}
   160  		case decision.FieldStartSuffix:
   161  			if value, ok := values[i].(*sql.NullInt64); !ok {
   162  				return fmt.Errorf("unexpected type %T for field start_suffix", values[i])
   163  			} else if value.Valid {
   164  				d.StartSuffix = value.Int64
   165  			}
   166  		case decision.FieldEndSuffix:
   167  			if value, ok := values[i].(*sql.NullInt64); !ok {
   168  				return fmt.Errorf("unexpected type %T for field end_suffix", values[i])
   169  			} else if value.Valid {
   170  				d.EndSuffix = value.Int64
   171  			}
   172  		case decision.FieldIPSize:
   173  			if value, ok := values[i].(*sql.NullInt64); !ok {
   174  				return fmt.Errorf("unexpected type %T for field ip_size", values[i])
   175  			} else if value.Valid {
   176  				d.IPSize = value.Int64
   177  			}
   178  		case decision.FieldScope:
   179  			if value, ok := values[i].(*sql.NullString); !ok {
   180  				return fmt.Errorf("unexpected type %T for field scope", values[i])
   181  			} else if value.Valid {
   182  				d.Scope = value.String
   183  			}
   184  		case decision.FieldValue:
   185  			if value, ok := values[i].(*sql.NullString); !ok {
   186  				return fmt.Errorf("unexpected type %T for field value", values[i])
   187  			} else if value.Valid {
   188  				d.Value = value.String
   189  			}
   190  		case decision.FieldOrigin:
   191  			if value, ok := values[i].(*sql.NullString); !ok {
   192  				return fmt.Errorf("unexpected type %T for field origin", values[i])
   193  			} else if value.Valid {
   194  				d.Origin = value.String
   195  			}
   196  		case decision.FieldSimulated:
   197  			if value, ok := values[i].(*sql.NullBool); !ok {
   198  				return fmt.Errorf("unexpected type %T for field simulated", values[i])
   199  			} else if value.Valid {
   200  				d.Simulated = value.Bool
   201  			}
   202  		case decision.FieldUUID:
   203  			if value, ok := values[i].(*sql.NullString); !ok {
   204  				return fmt.Errorf("unexpected type %T for field uuid", values[i])
   205  			} else if value.Valid {
   206  				d.UUID = value.String
   207  			}
   208  		case decision.FieldAlertDecisions:
   209  			if value, ok := values[i].(*sql.NullInt64); !ok {
   210  				return fmt.Errorf("unexpected type %T for field alert_decisions", values[i])
   211  			} else if value.Valid {
   212  				d.AlertDecisions = int(value.Int64)
   213  			}
   214  		default:
   215  			d.selectValues.Set(columns[i], values[i])
   216  		}
   217  	}
   218  	return nil
   219  }
   220  
   221  // GetValue returns the ent.Value that was dynamically selected and assigned to the Decision.
   222  // This includes values selected through modifiers, order, etc.
   223  func (d *Decision) GetValue(name string) (ent.Value, error) {
   224  	return d.selectValues.Get(name)
   225  }
   226  
   227  // QueryOwner queries the "owner" edge of the Decision entity.
   228  func (d *Decision) QueryOwner() *AlertQuery {
   229  	return NewDecisionClient(d.config).QueryOwner(d)
   230  }
   231  
   232  // Update returns a builder for updating this Decision.
   233  // Note that you need to call Decision.Unwrap() before calling this method if this Decision
   234  // was returned from a transaction, and the transaction was committed or rolled back.
   235  func (d *Decision) Update() *DecisionUpdateOne {
   236  	return NewDecisionClient(d.config).UpdateOne(d)
   237  }
   238  
   239  // Unwrap unwraps the Decision entity that was returned from a transaction after it was closed,
   240  // so that all future queries will be executed through the driver which created the transaction.
   241  func (d *Decision) Unwrap() *Decision {
   242  	_tx, ok := d.config.driver.(*txDriver)
   243  	if !ok {
   244  		panic("ent: Decision is not a transactional entity")
   245  	}
   246  	d.config.driver = _tx.drv
   247  	return d
   248  }
   249  
   250  // String implements the fmt.Stringer.
   251  func (d *Decision) String() string {
   252  	var builder strings.Builder
   253  	builder.WriteString("Decision(")
   254  	builder.WriteString(fmt.Sprintf("id=%v, ", d.ID))
   255  	if v := d.CreatedAt; v != nil {
   256  		builder.WriteString("created_at=")
   257  		builder.WriteString(v.Format(time.ANSIC))
   258  	}
   259  	builder.WriteString(", ")
   260  	if v := d.UpdatedAt; v != nil {
   261  		builder.WriteString("updated_at=")
   262  		builder.WriteString(v.Format(time.ANSIC))
   263  	}
   264  	builder.WriteString(", ")
   265  	if v := d.Until; v != nil {
   266  		builder.WriteString("until=")
   267  		builder.WriteString(v.Format(time.ANSIC))
   268  	}
   269  	builder.WriteString(", ")
   270  	builder.WriteString("scenario=")
   271  	builder.WriteString(d.Scenario)
   272  	builder.WriteString(", ")
   273  	builder.WriteString("type=")
   274  	builder.WriteString(d.Type)
   275  	builder.WriteString(", ")
   276  	builder.WriteString("start_ip=")
   277  	builder.WriteString(fmt.Sprintf("%v", d.StartIP))
   278  	builder.WriteString(", ")
   279  	builder.WriteString("end_ip=")
   280  	builder.WriteString(fmt.Sprintf("%v", d.EndIP))
   281  	builder.WriteString(", ")
   282  	builder.WriteString("start_suffix=")
   283  	builder.WriteString(fmt.Sprintf("%v", d.StartSuffix))
   284  	builder.WriteString(", ")
   285  	builder.WriteString("end_suffix=")
   286  	builder.WriteString(fmt.Sprintf("%v", d.EndSuffix))
   287  	builder.WriteString(", ")
   288  	builder.WriteString("ip_size=")
   289  	builder.WriteString(fmt.Sprintf("%v", d.IPSize))
   290  	builder.WriteString(", ")
   291  	builder.WriteString("scope=")
   292  	builder.WriteString(d.Scope)
   293  	builder.WriteString(", ")
   294  	builder.WriteString("value=")
   295  	builder.WriteString(d.Value)
   296  	builder.WriteString(", ")
   297  	builder.WriteString("origin=")
   298  	builder.WriteString(d.Origin)
   299  	builder.WriteString(", ")
   300  	builder.WriteString("simulated=")
   301  	builder.WriteString(fmt.Sprintf("%v", d.Simulated))
   302  	builder.WriteString(", ")
   303  	builder.WriteString("uuid=")
   304  	builder.WriteString(d.UUID)
   305  	builder.WriteString(", ")
   306  	builder.WriteString("alert_decisions=")
   307  	builder.WriteString(fmt.Sprintf("%v", d.AlertDecisions))
   308  	builder.WriteByte(')')
   309  	return builder.String()
   310  }
   311  
   312  // Decisions is a parsable slice of Decision.
   313  type Decisions []*Decision