// Code generated by gopkg.in/reform.v1. DO NOT EDIT.

package models

import (
	"fmt"
	"strings"

	"gopkg.in/reform.v1"
	"gopkg.in/reform.v1/parse"
)

type personTableType struct {
	s parse.StructInfo
	z []interface{}
}

// Schema returns a schema name in SQL database ("").
func (v *personTableType) Schema() string {
	return v.s.SQLSchema
}

// Name returns a view or table name in SQL database ("people").
func (v *personTableType) Name() string {
	return v.s.SQLName
}

// Columns returns a new slice of column names for that view or table in SQL database.
func (v *personTableType) Columns() []string {
	return []string{"id", "name", "email", "created_at", "updated_at"}
}

// NewStruct makes a new struct for that view or table.
func (v *personTableType) NewStruct() reform.Struct {
	return new(Person)
}

// NewRecord makes a new record for that table.
func (v *personTableType) NewRecord() reform.Record {
	return new(Person)
}

// PKColumnIndex returns an index of primary key column for that table in SQL database.
func (v *personTableType) PKColumnIndex() uint {
	return uint(v.s.PKFieldIndex)
}

// PersonTable represents people view or table in SQL database.
var PersonTable = &personTableType{
	s: parse.StructInfo{Type: "Person", SQLSchema: "", SQLName: "people", Fields: []parse.FieldInfo{{Name: "ID", Type: "int32", Column: "id"}, {Name: "Name", Type: "string", Column: "name"}, {Name: "Email", Type: "*string", Column: "email"}, {Name: "CreatedAt", Type: "time.Time", Column: "created_at"}, {Name: "UpdatedAt", Type: "*time.Time", Column: "updated_at"}}, PKFieldIndex: 0},
	z: new(Person).Values(),
}

// String returns a string representation of this struct or record.
func (s Person) String() string {
	res := make([]string, 5)
	res[0] = "ID: " + reform.Inspect(s.ID, true)
	res[1] = "Name: " + reform.Inspect(s.Name, true)
	res[2] = "Email: " + reform.Inspect(s.Email, true)
	res[3] = "CreatedAt: " + reform.Inspect(s.CreatedAt, true)
	res[4] = "UpdatedAt: " + reform.Inspect(s.UpdatedAt, true)
	return strings.Join(res, ", ")
}

// Values returns a slice of struct or record field values.
// Returned interface{} values are never untyped nils.
func (s *Person) Values() []interface{} {
	return []interface{}{
		s.ID,
		s.Name,
		s.Email,
		s.CreatedAt,
		s.UpdatedAt,
	}
}

// Pointers returns a slice of pointers to struct or record fields.
// Returned interface{} values are never untyped nils.
func (s *Person) Pointers() []interface{} {
	return []interface{}{
		&s.ID,
		&s.Name,
		&s.Email,
		&s.CreatedAt,
		&s.UpdatedAt,
	}
}

// View returns View object for that struct.
func (s *Person) View() reform.View {
	return PersonTable
}

// Table returns Table object for that record.
func (s *Person) Table() reform.Table {
	return PersonTable
}

// PKValue returns a value of primary key for that record.
// Returned interface{} value is never untyped nil.
func (s *Person) PKValue() interface{} {
	return s.ID
}

// PKPointer returns a pointer to primary key field for that record.
// Returned interface{} value is never untyped nil.
func (s *Person) PKPointer() interface{} {
	return &s.ID
}

// HasPK returns true if record has non-zero primary key set, false otherwise.
func (s *Person) HasPK() bool {
	return s.ID != PersonTable.z[PersonTable.s.PKFieldIndex]
}

// SetPK sets record primary key.
func (s *Person) SetPK(pk interface{}) {
	if i64, ok := pk.(int64); ok {
		s.ID = int32(i64)
	} else {
		s.ID = pk.(int32)
	}
}

// check interfaces
var (
	_ reform.View   = PersonTable
	_ reform.Struct = (*Person)(nil)
	_ reform.Table  = PersonTable
	_ reform.Record = (*Person)(nil)
	_ fmt.Stringer  = (*Person)(nil)
)

func init() {
	parse.AssertUpToDate(&PersonTable.s, new(Person))
}
