package models

import "time"

type Account struct {
	ID        string        `json:"id" bson:"_id,omitempty"`
	UserID    string        `json:"userId" bson:"userId"`
	Cart      []string      `json:"cart" bson:"cart"`
	Wallet    Wallet        `json:"wallet" bson:"wallet"`
	Name      Name          `json:"name" bson:"name"`
	Status    AccountStatus `json:"status" bson:"status"`
	Deleted   bool          `json:"isDeleted" bson:"isDeleted"`
	CreatedAt time.Time     `json:"createdAt" bson:"createdAt"`
	UpdatedAt time.Time     `json:"updatedAt" bson:"updatedAt"`
	DeletedAt *time.Time    `json:"deletedAt,omitempty" bson:"deletedAt,omitempty"`
	From      string        `json:"from" bson:"from"`
	Partner   string        `json:"partner" bson:"partner"`
	Version   uint32        `json:"version" bson:"version"`
}

func (receiver *Account) Sanitize() *Account {
	now := time.Now()

	receiver.ID = ""
	receiver.Cart = []string{}
	receiver.Wallet = Wallet{}
	receiver.Name = Name{}
	receiver.Status = DefaultAccountStatus
	receiver.CreatedAt = now
	receiver.UpdatedAt = now
	// закоментил, потому что при инзерте они всегда будут ""
	//receiver.From = ""
	//receiver.Partner = ""
	receiver.DeletedAt = nil
	receiver.Deleted = false
	receiver.Version = mongoVersion

	return receiver
}

type Name struct {
	Middlename string `json:"middlename,omitempty"`
	FirstName  string `json:"firstname,omitempty"`
	Orgname    string `json:"orgname,omitempty"`
	Secondname string `json:"secondname,omitempty"`
}

type SetAccountStatus struct {
	Status AccountStatus `json:"status"`
}

type AccountStatus string

const (
	AccountStatusNko     AccountStatus = "nko"
	AccountStatusNo      AccountStatus = "no"
	AccountStatusOrg     AccountStatus = "org"
	DefaultAccountStatus AccountStatus = AccountStatusNo
)
