// Code generated by entc, DO NOT EDIT.

package ent

import (
	"fmt"
	"strings"
	"time"

	"entgo.io/ent/dialect/sql"

	"github.com/pingcap/test-infra/common/model"
	"github.com/pingcap/test-infra/services/tcms/service/store/v2/ent/casetriage"
)

// CaseTriage is the model entity for the CaseTriage schema.
type CaseTriage struct {
	config `json:"-"`
	// ID of the ent.
	ID model.ID `json:"id,omitempty"`
	// CreatedAt holds the value of the "createdAt" field.
	CreatedAt time.Time `json:"createdAt,omitempty"`
	// UpdatedAt holds the value of the "updatedAt" field.
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
	// PlanExecutionID holds the value of the "planExecutionID" field.
	PlanExecutionID model.ID `json:"planExecutionID,omitempty"`
	// PlanID holds the value of the "planID" field.
	PlanID model.ID `json:"planID,omitempty"`
	// CaseExecutionID holds the value of the "caseExecutionID" field.
	CaseExecutionID model.ID `json:"caseExecutionID,omitempty"`
	// CaseID holds the value of the "caseID" field.
	CaseID model.ID `json:"caseID,omitempty"`
	// Reason holds the value of the "reason" field.
	Reason model.CaseExecFailReason `json:"reason,omitempty"`
	// Solution holds the value of the "solution" field.
	Solution model.ExecFailSolution `json:"solution,omitempty"`
	// IssueLink holds the value of the "issueLink" field.
	IssueLink string `json:"issueLink,omitempty"`
	// Note holds the value of the "note" field.
	Note string `json:"note,omitempty"`
	// ForkedFrom holds the value of the "forkedFrom" field.
	ForkedFrom model.ID `json:"forkedFrom,omitempty"`
}

// scanValues returns the types for scanning values from sql.Rows.
func (*CaseTriage) scanValues(columns []string) ([]interface{}, error) {
	values := make([]interface{}, len(columns))
	for i := range columns {
		switch columns[i] {
		case casetriage.FieldID, casetriage.FieldPlanExecutionID, casetriage.FieldPlanID, casetriage.FieldCaseExecutionID, casetriage.FieldCaseID, casetriage.FieldForkedFrom:
			values[i] = new(sql.NullInt64)
		case casetriage.FieldReason, casetriage.FieldSolution, casetriage.FieldIssueLink, casetriage.FieldNote:
			values[i] = new(sql.NullString)
		case casetriage.FieldCreatedAt, casetriage.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		default:
			return nil, fmt.Errorf("unexpected column %q for type CaseTriage", columns[i])
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the CaseTriage fields.
func (ct *CaseTriage) assignValues(columns []string, values []interface{}) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case casetriage.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			ct.ID = model.ID(value.Int64)
		case casetriage.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field createdAt", values[i])
			} else if value.Valid {
				ct.CreatedAt = value.Time
			}
		case casetriage.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updatedAt", values[i])
			} else if value.Valid {
				ct.UpdatedAt = value.Time
			}
		case casetriage.FieldPlanExecutionID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field planExecutionID", values[i])
			} else if value.Valid {
				ct.PlanExecutionID = model.ID(value.Int64)
			}
		case casetriage.FieldPlanID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field planID", values[i])
			} else if value.Valid {
				ct.PlanID = model.ID(value.Int64)
			}
		case casetriage.FieldCaseExecutionID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field caseExecutionID", values[i])
			} else if value.Valid {
				ct.CaseExecutionID = model.ID(value.Int64)
			}
		case casetriage.FieldCaseID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field caseID", values[i])
			} else if value.Valid {
				ct.CaseID = model.ID(value.Int64)
			}
		case casetriage.FieldReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field reason", values[i])
			} else if value.Valid {
				ct.Reason = model.CaseExecFailReason(value.String)
			}
		case casetriage.FieldSolution:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field solution", values[i])
			} else if value.Valid {
				ct.Solution = model.ExecFailSolution(value.String)
			}
		case casetriage.FieldIssueLink:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field issueLink", values[i])
			} else if value.Valid {
				ct.IssueLink = value.String
			}
		case casetriage.FieldNote:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field note", values[i])
			} else if value.Valid {
				ct.Note = value.String
			}
		case casetriage.FieldForkedFrom:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field forkedFrom", values[i])
			} else if value.Valid {
				ct.ForkedFrom = model.ID(value.Int64)
			}
		}
	}
	return nil
}

// Update returns a builder for updating this CaseTriage.
// Note that you need to call CaseTriage.Unwrap() before calling this method if this CaseTriage
// was returned from a transaction, and the transaction was committed or rolled back.
func (ct *CaseTriage) Update() *CaseTriageUpdateOne {
	return (&CaseTriageClient{config: ct.config}).UpdateOne(ct)
}

// Unwrap unwraps the CaseTriage entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (ct *CaseTriage) Unwrap() *CaseTriage {
	tx, ok := ct.config.driver.(*txDriver)
	if !ok {
		panic("ent: CaseTriage is not a transactional entity")
	}
	ct.config.driver = tx.drv
	return ct
}

// String implements the fmt.Stringer.
func (ct *CaseTriage) String() string {
	var builder strings.Builder
	builder.WriteString("CaseTriage(")
	builder.WriteString(fmt.Sprintf("id=%v", ct.ID))
	builder.WriteString(", createdAt=")
	builder.WriteString(ct.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", updatedAt=")
	builder.WriteString(ct.UpdatedAt.Format(time.ANSIC))
	builder.WriteString(", planExecutionID=")
	builder.WriteString(fmt.Sprintf("%v", ct.PlanExecutionID))
	builder.WriteString(", planID=")
	builder.WriteString(fmt.Sprintf("%v", ct.PlanID))
	builder.WriteString(", caseExecutionID=")
	builder.WriteString(fmt.Sprintf("%v", ct.CaseExecutionID))
	builder.WriteString(", caseID=")
	builder.WriteString(fmt.Sprintf("%v", ct.CaseID))
	builder.WriteString(", reason=")
	builder.WriteString(fmt.Sprintf("%v", ct.Reason))
	builder.WriteString(", solution=")
	builder.WriteString(fmt.Sprintf("%v", ct.Solution))
	builder.WriteString(", issueLink=")
	builder.WriteString(ct.IssueLink)
	builder.WriteString(", note=")
	builder.WriteString(ct.Note)
	builder.WriteString(", forkedFrom=")
	builder.WriteString(fmt.Sprintf("%v", ct.ForkedFrom))
	builder.WriteByte(')')
	return builder.String()
}

// CaseTriages is a parsable slice of CaseTriage.
type CaseTriages []*CaseTriage

func (ct CaseTriages) config(cfg config) {
	for _i := range ct {
		ct[_i].config = cfg
	}
}
