// Code generated by ent, DO NOT EDIT.

package models

import (
	"fmt"
	"juwan-backend/app/dispute/rpc/internal/models/disputes"
	"juwan-backend/pkg/types"
	"strings"
	"time"

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

// Disputes is the model entity for the Disputes schema.
type Disputes struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// OrderID holds the value of the "order_id" field.
	OrderID int64 `json:"order_id,omitempty"`
	// InitiatorID holds the value of the "initiator_id" field.
	InitiatorID int64 `json:"initiator_id,omitempty"`
	// InitiatorName holds the value of the "initiator_name" field.
	InitiatorName string `json:"initiator_name,omitempty"`
	// RespondentID holds the value of the "respondent_id" field.
	RespondentID int64 `json:"respondent_id,omitempty"`
	// Reason holds the value of the "reason" field.
	Reason string `json:"reason,omitempty"`
	// Evidence holds the value of the "evidence" field.
	Evidence types.TextArray `json:"evidence,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
	// Result holds the value of the "result" field.
	Result *string `json:"result,omitempty"`
	// RespondentReason holds the value of the "respondent_reason" field.
	RespondentReason *string `json:"respondent_reason,omitempty"`
	// RespondentEvidence holds the value of the "respondent_evidence" field.
	RespondentEvidence types.TextArray `json:"respondent_evidence,omitempty"`
	// AppealReason holds the value of the "appeal_reason" field.
	AppealReason *string `json:"appeal_reason,omitempty"`
	// AppealedAt holds the value of the "appealed_at" field.
	AppealedAt *time.Time `json:"appealed_at,omitempty"`
	// ResolvedBy holds the value of the "resolved_by" field.
	ResolvedBy *int64 `json:"resolved_by,omitempty"`
	// ResolvedAt holds the value of the "resolved_at" field.
	ResolvedAt *time.Time `json:"resolved_at,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt    time.Time `json:"updated_at,omitempty"`
	selectValues sql.SelectValues
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Disputes) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case disputes.FieldID, disputes.FieldOrderID, disputes.FieldInitiatorID, disputes.FieldRespondentID, disputes.FieldResolvedBy:
			values[i] = new(sql.NullInt64)
		case disputes.FieldInitiatorName, disputes.FieldReason, disputes.FieldStatus, disputes.FieldResult, disputes.FieldRespondentReason, disputes.FieldAppealReason:
			values[i] = new(sql.NullString)
		case disputes.FieldAppealedAt, disputes.FieldResolvedAt, disputes.FieldCreatedAt, disputes.FieldUpdatedAt:
			values[i] = new(sql.NullTime)
		case disputes.FieldEvidence, disputes.FieldRespondentEvidence:
			values[i] = new(types.TextArray)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Disputes fields.
func (_m *Disputes) assignValues(columns []string, values []any) 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 disputes.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			_m.ID = int64(value.Int64)
		case disputes.FieldOrderID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field order_id", values[i])
			} else if value.Valid {
				_m.OrderID = value.Int64
			}
		case disputes.FieldInitiatorID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field initiator_id", values[i])
			} else if value.Valid {
				_m.InitiatorID = value.Int64
			}
		case disputes.FieldInitiatorName:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field initiator_name", values[i])
			} else if value.Valid {
				_m.InitiatorName = value.String
			}
		case disputes.FieldRespondentID:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field respondent_id", values[i])
			} else if value.Valid {
				_m.RespondentID = value.Int64
			}
		case disputes.FieldReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field reason", values[i])
			} else if value.Valid {
				_m.Reason = value.String
			}
		case disputes.FieldEvidence:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field evidence", values[i])
			} else if value != nil {
				_m.Evidence = *value
			}
		case disputes.FieldStatus:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field status", values[i])
			} else if value.Valid {
				_m.Status = value.String
			}
		case disputes.FieldResult:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field result", values[i])
			} else if value.Valid {
				_m.Result = new(string)
				*_m.Result = value.String
			}
		case disputes.FieldRespondentReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field respondent_reason", values[i])
			} else if value.Valid {
				_m.RespondentReason = new(string)
				*_m.RespondentReason = value.String
			}
		case disputes.FieldRespondentEvidence:
			if value, ok := values[i].(*types.TextArray); !ok {
				return fmt.Errorf("unexpected type %T for field respondent_evidence", values[i])
			} else if value != nil {
				_m.RespondentEvidence = *value
			}
		case disputes.FieldAppealReason:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field appeal_reason", values[i])
			} else if value.Valid {
				_m.AppealReason = new(string)
				*_m.AppealReason = value.String
			}
		case disputes.FieldAppealedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field appealed_at", values[i])
			} else if value.Valid {
				_m.AppealedAt = new(time.Time)
				*_m.AppealedAt = value.Time
			}
		case disputes.FieldResolvedBy:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for field resolved_by", values[i])
			} else if value.Valid {
				_m.ResolvedBy = new(int64)
				*_m.ResolvedBy = value.Int64
			}
		case disputes.FieldResolvedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field resolved_at", values[i])
			} else if value.Valid {
				_m.ResolvedAt = new(time.Time)
				*_m.ResolvedAt = value.Time
			}
		case disputes.FieldCreatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field created_at", values[i])
			} else if value.Valid {
				_m.CreatedAt = value.Time
			}
		case disputes.FieldUpdatedAt:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
			} else if value.Valid {
				_m.UpdatedAt = value.Time
			}
		default:
			_m.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the Disputes.
// This includes values selected through modifiers, order, etc.
func (_m *Disputes) Value(name string) (ent.Value, error) {
	return _m.selectValues.Get(name)
}

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

// Unwrap unwraps the Disputes 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 (_m *Disputes) Unwrap() *Disputes {
	_tx, ok := _m.config.driver.(*txDriver)
	if !ok {
		panic("models: Disputes is not a transactional entity")
	}
	_m.config.driver = _tx.drv
	return _m
}

// String implements the fmt.Stringer.
func (_m *Disputes) String() string {
	var builder strings.Builder
	builder.WriteString("Disputes(")
	builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
	builder.WriteString("order_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.OrderID))
	builder.WriteString(", ")
	builder.WriteString("initiator_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.InitiatorID))
	builder.WriteString(", ")
	builder.WriteString("initiator_name=")
	builder.WriteString(_m.InitiatorName)
	builder.WriteString(", ")
	builder.WriteString("respondent_id=")
	builder.WriteString(fmt.Sprintf("%v", _m.RespondentID))
	builder.WriteString(", ")
	builder.WriteString("reason=")
	builder.WriteString(_m.Reason)
	builder.WriteString(", ")
	builder.WriteString("evidence=")
	builder.WriteString(fmt.Sprintf("%v", _m.Evidence))
	builder.WriteString(", ")
	builder.WriteString("status=")
	builder.WriteString(_m.Status)
	builder.WriteString(", ")
	if v := _m.Result; v != nil {
		builder.WriteString("result=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.RespondentReason; v != nil {
		builder.WriteString("respondent_reason=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	builder.WriteString("respondent_evidence=")
	builder.WriteString(fmt.Sprintf("%v", _m.RespondentEvidence))
	builder.WriteString(", ")
	if v := _m.AppealReason; v != nil {
		builder.WriteString("appeal_reason=")
		builder.WriteString(*v)
	}
	builder.WriteString(", ")
	if v := _m.AppealedAt; v != nil {
		builder.WriteString("appealed_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	if v := _m.ResolvedBy; v != nil {
		builder.WriteString("resolved_by=")
		builder.WriteString(fmt.Sprintf("%v", *v))
	}
	builder.WriteString(", ")
	if v := _m.ResolvedAt; v != nil {
		builder.WriteString("resolved_at=")
		builder.WriteString(v.Format(time.ANSIC))
	}
	builder.WriteString(", ")
	builder.WriteString("created_at=")
	builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
	builder.WriteString(", ")
	builder.WriteString("updated_at=")
	builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// DisputesSlice is a parsable slice of Disputes.
type DisputesSlice []*Disputes
