// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.

package models

import (
	"context"
	"fmt"
	"io"

	"github.com/Gleipnir-Technology/bob"
	"github.com/Gleipnir-Technology/bob/dialect/psql"
	"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
	"github.com/Gleipnir-Technology/bob/dialect/psql/dm"
	"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
	"github.com/Gleipnir-Technology/bob/dialect/psql/um"
	"github.com/Gleipnir-Technology/bob/expr"
	"github.com/Gleipnir-Technology/bob/orm"
	"github.com/Gleipnir-Technology/bob/types/pgtypes"
	"github.com/aarondl/opt/omit"
)

// FileuploadErrorCSV is an object representing the database table.
type FileuploadErrorCSV struct {
	Col       int32  `db:"col" `
	CSVFileID int32  `db:"csv_file_id" `
	ID        int32  `db:"id,pk" `
	Line      int32  `db:"line" `
	Message   string `db:"message" `

	R fileuploadErrorCSVR `db:"-" `
}

// FileuploadErrorCSVSlice is an alias for a slice of pointers to FileuploadErrorCSV.
// This should almost always be used instead of []*FileuploadErrorCSV.
type FileuploadErrorCSVSlice []*FileuploadErrorCSV

// FileuploadErrorCSVS contains methods to work with the error_csv table
var FileuploadErrorCSVS = psql.NewTablex[*FileuploadErrorCSV, FileuploadErrorCSVSlice, *FileuploadErrorCSVSetter]("fileupload", "error_csv", buildFileuploadErrorCSVColumns("fileupload.error_csv"))

// FileuploadErrorCSVSQuery is a query on the error_csv table
type FileuploadErrorCSVSQuery = *psql.ViewQuery[*FileuploadErrorCSV, FileuploadErrorCSVSlice]

// fileuploadErrorCSVR is where relationships are stored.
type fileuploadErrorCSVR struct {
	CSVFileCSV *FileuploadCSV // fileupload.error_csv.error_csv_csv_file_id_fkey
}

func buildFileuploadErrorCSVColumns(alias string) fileuploadErrorCSVColumns {
	return fileuploadErrorCSVColumns{
		ColumnsExpr: expr.NewColumnsExpr(
			"col", "csv_file_id", "id", "line", "message",
		).WithParent("fileupload.error_csv"),
		tableAlias: alias,
		Col:        psql.Quote(alias, "col"),
		CSVFileID:  psql.Quote(alias, "csv_file_id"),
		ID:         psql.Quote(alias, "id"),
		Line:       psql.Quote(alias, "line"),
		Message:    psql.Quote(alias, "message"),
	}
}

type fileuploadErrorCSVColumns struct {
	expr.ColumnsExpr
	tableAlias string
	Col        psql.Expression
	CSVFileID  psql.Expression
	ID         psql.Expression
	Line       psql.Expression
	Message    psql.Expression
}

func (c fileuploadErrorCSVColumns) Alias() string {
	return c.tableAlias
}

func (fileuploadErrorCSVColumns) AliasedAs(alias string) fileuploadErrorCSVColumns {
	return buildFileuploadErrorCSVColumns(alias)
}

// FileuploadErrorCSVSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type FileuploadErrorCSVSetter struct {
	Col       omit.Val[int32]  `db:"col" `
	CSVFileID omit.Val[int32]  `db:"csv_file_id" `
	ID        omit.Val[int32]  `db:"id,pk" `
	Line      omit.Val[int32]  `db:"line" `
	Message   omit.Val[string] `db:"message" `
}

func (s FileuploadErrorCSVSetter) SetColumns() []string {
	vals := make([]string, 0, 5)
	if s.Col.IsValue() {
		vals = append(vals, "col")
	}
	if s.CSVFileID.IsValue() {
		vals = append(vals, "csv_file_id")
	}
	if s.ID.IsValue() {
		vals = append(vals, "id")
	}
	if s.Line.IsValue() {
		vals = append(vals, "line")
	}
	if s.Message.IsValue() {
		vals = append(vals, "message")
	}
	return vals
}

func (s FileuploadErrorCSVSetter) Overwrite(t *FileuploadErrorCSV) {
	if s.Col.IsValue() {
		t.Col = s.Col.MustGet()
	}
	if s.CSVFileID.IsValue() {
		t.CSVFileID = s.CSVFileID.MustGet()
	}
	if s.ID.IsValue() {
		t.ID = s.ID.MustGet()
	}
	if s.Line.IsValue() {
		t.Line = s.Line.MustGet()
	}
	if s.Message.IsValue() {
		t.Message = s.Message.MustGet()
	}
}

func (s *FileuploadErrorCSVSetter) Apply(q *dialect.InsertQuery) {
	q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
		return FileuploadErrorCSVS.BeforeInsertHooks.RunHooks(ctx, exec, s)
	})

	q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
		vals := make([]bob.Expression, 5)
		if s.Col.IsValue() {
			vals[0] = psql.Arg(s.Col.MustGet())
		} else {
			vals[0] = psql.Raw("DEFAULT")
		}

		if s.CSVFileID.IsValue() {
			vals[1] = psql.Arg(s.CSVFileID.MustGet())
		} else {
			vals[1] = psql.Raw("DEFAULT")
		}

		if s.ID.IsValue() {
			vals[2] = psql.Arg(s.ID.MustGet())
		} else {
			vals[2] = psql.Raw("DEFAULT")
		}

		if s.Line.IsValue() {
			vals[3] = psql.Arg(s.Line.MustGet())
		} else {
			vals[3] = psql.Raw("DEFAULT")
		}

		if s.Message.IsValue() {
			vals[4] = psql.Arg(s.Message.MustGet())
		} else {
			vals[4] = psql.Raw("DEFAULT")
		}

		return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
	}))
}

func (s FileuploadErrorCSVSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
	return um.Set(s.Expressions()...)
}

func (s FileuploadErrorCSVSetter) Expressions(prefix ...string) []bob.Expression {
	exprs := make([]bob.Expression, 0, 5)

	if s.Col.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			psql.Quote(append(prefix, "col")...),
			psql.Arg(s.Col),
		}})
	}

	if s.CSVFileID.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			psql.Quote(append(prefix, "csv_file_id")...),
			psql.Arg(s.CSVFileID),
		}})
	}

	if s.ID.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			psql.Quote(append(prefix, "id")...),
			psql.Arg(s.ID),
		}})
	}

	if s.Line.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			psql.Quote(append(prefix, "line")...),
			psql.Arg(s.Line),
		}})
	}

	if s.Message.IsValue() {
		exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
			psql.Quote(append(prefix, "message")...),
			psql.Arg(s.Message),
		}})
	}

	return exprs
}

// FindFileuploadErrorCSV retrieves a single record by primary key
// If cols is empty Find will return all columns.
func FindFileuploadErrorCSV(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*FileuploadErrorCSV, error) {
	if len(cols) == 0 {
		return FileuploadErrorCSVS.Query(
			sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
		).One(ctx, exec)
	}

	return FileuploadErrorCSVS.Query(
		sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
		sm.Columns(FileuploadErrorCSVS.Columns.Only(cols...)),
	).One(ctx, exec)
}

// FileuploadErrorCSVExists checks the presence of a single record by primary key
func FileuploadErrorCSVExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
	return FileuploadErrorCSVS.Query(
		sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(IDPK))),
	).Exists(ctx, exec)
}

// AfterQueryHook is called after FileuploadErrorCSV is retrieved from the database
func (o *FileuploadErrorCSV) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
	var err error

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = FileuploadErrorCSVS.AfterSelectHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
	case bob.QueryTypeInsert:
		ctx, err = FileuploadErrorCSVS.AfterInsertHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
	case bob.QueryTypeUpdate:
		ctx, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
	case bob.QueryTypeDelete:
		ctx, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadErrorCSVSlice{o})
	}

	return err
}

// primaryKeyVals returns the primary key values of the FileuploadErrorCSV
func (o *FileuploadErrorCSV) primaryKeyVals() bob.Expression {
	return psql.Arg(o.ID)
}

func (o *FileuploadErrorCSV) pkEQ() dialect.Expression {
	return psql.Quote("fileupload.error_csv", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
		return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
	}))
}

// Update uses an executor to update the FileuploadErrorCSV
func (o *FileuploadErrorCSV) Update(ctx context.Context, exec bob.Executor, s *FileuploadErrorCSVSetter) error {
	v, err := FileuploadErrorCSVS.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec)
	if err != nil {
		return err
	}

	o.R = v.R
	*o = *v

	return nil
}

// Delete deletes a single FileuploadErrorCSV record with an executor
func (o *FileuploadErrorCSV) Delete(ctx context.Context, exec bob.Executor) error {
	_, err := FileuploadErrorCSVS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec)
	return err
}

// Reload refreshes the FileuploadErrorCSV using the executor
func (o *FileuploadErrorCSV) Reload(ctx context.Context, exec bob.Executor) error {
	o2, err := FileuploadErrorCSVS.Query(
		sm.Where(FileuploadErrorCSVS.Columns.ID.EQ(psql.Arg(o.ID))),
	).One(ctx, exec)
	if err != nil {
		return err
	}
	o2.R = o.R
	*o = *o2

	return nil
}

// AfterQueryHook is called after FileuploadErrorCSVSlice is retrieved from the database
func (o FileuploadErrorCSVSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
	var err error

	switch queryType {
	case bob.QueryTypeSelect:
		ctx, err = FileuploadErrorCSVS.AfterSelectHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeInsert:
		ctx, err = FileuploadErrorCSVS.AfterInsertHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeUpdate:
		ctx, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, o)
	case bob.QueryTypeDelete:
		ctx, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, o)
	}

	return err
}

func (o FileuploadErrorCSVSlice) pkIN() dialect.Expression {
	if len(o) == 0 {
		return psql.Raw("NULL")
	}

	return psql.Quote("fileupload.error_csv", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
		pkPairs := make([]bob.Expression, len(o))
		for i, row := range o {
			pkPairs[i] = row.primaryKeyVals()
		}
		return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "")
	}))
}

// copyMatchingRows finds models in the given slice that have the same primary key
// then it first copies the existing relationships from the old model to the new model
// and then replaces the old model in the slice with the new model
func (o FileuploadErrorCSVSlice) copyMatchingRows(from ...*FileuploadErrorCSV) {
	for i, old := range o {
		for _, new := range from {
			if new.ID != old.ID {
				continue
			}
			new.R = old.R
			o[i] = new
			break
		}
	}
}

// UpdateMod modifies an update query with "WHERE primary_key IN (o...)"
func (o FileuploadErrorCSVSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
	return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) {
		q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
			return FileuploadErrorCSVS.BeforeUpdateHooks.RunHooks(ctx, exec, o)
		})

		q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
			var err error
			switch retrieved := retrieved.(type) {
			case *FileuploadErrorCSV:
				o.copyMatchingRows(retrieved)
			case []*FileuploadErrorCSV:
				o.copyMatchingRows(retrieved...)
			case FileuploadErrorCSVSlice:
				o.copyMatchingRows(retrieved...)
			default:
				// If the retrieved value is not a FileuploadErrorCSV or a slice of FileuploadErrorCSV
				// then run the AfterUpdateHooks on the slice
				_, err = FileuploadErrorCSVS.AfterUpdateHooks.RunHooks(ctx, exec, o)
			}

			return err
		}))

		q.AppendWhere(o.pkIN())
	})
}

// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)"
func (o FileuploadErrorCSVSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] {
	return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) {
		q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) {
			return FileuploadErrorCSVS.BeforeDeleteHooks.RunHooks(ctx, exec, o)
		})

		q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error {
			var err error
			switch retrieved := retrieved.(type) {
			case *FileuploadErrorCSV:
				o.copyMatchingRows(retrieved)
			case []*FileuploadErrorCSV:
				o.copyMatchingRows(retrieved...)
			case FileuploadErrorCSVSlice:
				o.copyMatchingRows(retrieved...)
			default:
				// If the retrieved value is not a FileuploadErrorCSV or a slice of FileuploadErrorCSV
				// then run the AfterDeleteHooks on the slice
				_, err = FileuploadErrorCSVS.AfterDeleteHooks.RunHooks(ctx, exec, o)
			}

			return err
		}))

		q.AppendWhere(o.pkIN())
	})
}

func (o FileuploadErrorCSVSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadErrorCSVSetter) error {
	if len(o) == 0 {
		return nil
	}

	_, err := FileuploadErrorCSVS.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec)
	return err
}

func (o FileuploadErrorCSVSlice) DeleteAll(ctx context.Context, exec bob.Executor) error {
	if len(o) == 0 {
		return nil
	}

	_, err := FileuploadErrorCSVS.Delete(o.DeleteMod()).Exec(ctx, exec)
	return err
}

func (o FileuploadErrorCSVSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
	if len(o) == 0 {
		return nil
	}

	o2, err := FileuploadErrorCSVS.Query(sm.Where(o.pkIN())).All(ctx, exec)
	if err != nil {
		return err
	}

	o.copyMatchingRows(o2...)

	return nil
}

// CSVFileCSV starts a query for related objects on fileupload.csv
func (o *FileuploadErrorCSV) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
	return FileuploadCSVS.Query(append(mods,
		sm.Where(FileuploadCSVS.Columns.FileID.EQ(psql.Arg(o.CSVFileID))),
	)...)
}

func (os FileuploadErrorCSVSlice) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery {
	pkCSVFileID := make(pgtypes.Array[int32], 0, len(os))
	for _, o := range os {
		if o == nil {
			continue
		}
		pkCSVFileID = append(pkCSVFileID, o.CSVFileID)
	}
	PKArgExpr := psql.Select(sm.Columns(
		psql.F("unnest", psql.Cast(psql.Arg(pkCSVFileID), "integer[]")),
	))

	return FileuploadCSVS.Query(append(mods,
		sm.Where(psql.Group(FileuploadCSVS.Columns.FileID).OP("IN", PKArgExpr)),
	)...)
}

func attachFileuploadErrorCSVCSVFileCSV0(ctx context.Context, exec bob.Executor, count int, fileuploadErrorCSV0 *FileuploadErrorCSV, fileuploadCSV1 *FileuploadCSV) (*FileuploadErrorCSV, error) {
	setter := &FileuploadErrorCSVSetter{
		CSVFileID: omit.From(fileuploadCSV1.FileID),
	}

	err := fileuploadErrorCSV0.Update(ctx, exec, setter)
	if err != nil {
		return nil, fmt.Errorf("attachFileuploadErrorCSVCSVFileCSV0: %w", err)
	}

	return fileuploadErrorCSV0, nil
}

func (fileuploadErrorCSV0 *FileuploadErrorCSV) InsertCSVFileCSV(ctx context.Context, exec bob.Executor, related *FileuploadCSVSetter) error {
	var err error

	fileuploadCSV1, err := FileuploadCSVS.Insert(related).One(ctx, exec)
	if err != nil {
		return fmt.Errorf("inserting related objects: %w", err)
	}

	_, err = attachFileuploadErrorCSVCSVFileCSV0(ctx, exec, 1, fileuploadErrorCSV0, fileuploadCSV1)
	if err != nil {
		return err
	}

	fileuploadErrorCSV0.R.CSVFileCSV = fileuploadCSV1

	fileuploadCSV1.R.CSVFileErrorCSVS = append(fileuploadCSV1.R.CSVFileErrorCSVS, fileuploadErrorCSV0)

	return nil
}

func (fileuploadErrorCSV0 *FileuploadErrorCSV) AttachCSVFileCSV(ctx context.Context, exec bob.Executor, fileuploadCSV1 *FileuploadCSV) error {
	var err error

	_, err = attachFileuploadErrorCSVCSVFileCSV0(ctx, exec, 1, fileuploadErrorCSV0, fileuploadCSV1)
	if err != nil {
		return err
	}

	fileuploadErrorCSV0.R.CSVFileCSV = fileuploadCSV1

	fileuploadCSV1.R.CSVFileErrorCSVS = append(fileuploadCSV1.R.CSVFileErrorCSVS, fileuploadErrorCSV0)

	return nil
}

type fileuploadErrorCSVWhere[Q psql.Filterable] struct {
	Col       psql.WhereMod[Q, int32]
	CSVFileID psql.WhereMod[Q, int32]
	ID        psql.WhereMod[Q, int32]
	Line      psql.WhereMod[Q, int32]
	Message   psql.WhereMod[Q, string]
}

func (fileuploadErrorCSVWhere[Q]) AliasedAs(alias string) fileuploadErrorCSVWhere[Q] {
	return buildFileuploadErrorCSVWhere[Q](buildFileuploadErrorCSVColumns(alias))
}

func buildFileuploadErrorCSVWhere[Q psql.Filterable](cols fileuploadErrorCSVColumns) fileuploadErrorCSVWhere[Q] {
	return fileuploadErrorCSVWhere[Q]{
		Col:       psql.Where[Q, int32](cols.Col),
		CSVFileID: psql.Where[Q, int32](cols.CSVFileID),
		ID:        psql.Where[Q, int32](cols.ID),
		Line:      psql.Where[Q, int32](cols.Line),
		Message:   psql.Where[Q, string](cols.Message),
	}
}

func (o *FileuploadErrorCSV) Preload(name string, retrieved any) error {
	if o == nil {
		return nil
	}

	switch name {
	case "CSVFileCSV":
		rel, ok := retrieved.(*FileuploadCSV)
		if !ok {
			return fmt.Errorf("fileuploadErrorCSV cannot load %T as %q", retrieved, name)
		}

		o.R.CSVFileCSV = rel

		if rel != nil {
			rel.R.CSVFileErrorCSVS = FileuploadErrorCSVSlice{o}
		}
		return nil
	default:
		return fmt.Errorf("fileuploadErrorCSV has no relationship %q", name)
	}
}

type fileuploadErrorCSVPreloader struct {
	CSVFileCSV func(...psql.PreloadOption) psql.Preloader
}

func buildFileuploadErrorCSVPreloader() fileuploadErrorCSVPreloader {
	return fileuploadErrorCSVPreloader{
		CSVFileCSV: func(opts ...psql.PreloadOption) psql.Preloader {
			return psql.Preload[*FileuploadCSV, FileuploadCSVSlice](psql.PreloadRel{
				Name: "CSVFileCSV",
				Sides: []psql.PreloadSide{
					{
						From:        FileuploadErrorCSVS,
						To:          FileuploadCSVS,
						FromColumns: []string{"csv_file_id"},
						ToColumns:   []string{"file_id"},
					},
				},
			}, FileuploadCSVS.Columns.Names(), opts...)
		},
	}
}

type fileuploadErrorCSVThenLoader[Q orm.Loadable] struct {
	CSVFileCSV func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
}

func buildFileuploadErrorCSVThenLoader[Q orm.Loadable]() fileuploadErrorCSVThenLoader[Q] {
	type CSVFileCSVLoadInterface interface {
		LoadCSVFileCSV(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
	}

	return fileuploadErrorCSVThenLoader[Q]{
		CSVFileCSV: thenLoadBuilder[Q](
			"CSVFileCSV",
			func(ctx context.Context, exec bob.Executor, retrieved CSVFileCSVLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
				return retrieved.LoadCSVFileCSV(ctx, exec, mods...)
			},
		),
	}
}

// LoadCSVFileCSV loads the fileuploadErrorCSV's CSVFileCSV into the .R struct
func (o *FileuploadErrorCSV) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
	if o == nil {
		return nil
	}

	// Reset the relationship
	o.R.CSVFileCSV = nil

	related, err := o.CSVFileCSV(mods...).One(ctx, exec)
	if err != nil {
		return err
	}

	related.R.CSVFileErrorCSVS = FileuploadErrorCSVSlice{o}

	o.R.CSVFileCSV = related
	return nil
}

// LoadCSVFileCSV loads the fileuploadErrorCSV's CSVFileCSV into the .R struct
func (os FileuploadErrorCSVSlice) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
	if len(os) == 0 {
		return nil
	}

	fileuploadCSVS, err := os.CSVFileCSV(mods...).All(ctx, exec)
	if err != nil {
		return err
	}

	for _, o := range os {
		if o == nil {
			continue
		}

		for _, rel := range fileuploadCSVS {

			if !(o.CSVFileID == rel.FileID) {
				continue
			}

			rel.R.CSVFileErrorCSVS = append(rel.R.CSVFileErrorCSVS, o)

			o.R.CSVFileCSV = rel
			break
		}
	}

	return nil
}
