package models

import (
	"errors"

	"github.com/jinzhu/gorm"
)

// User user
type User struct {
	gorm.Model
	RecordId   string `gorm:"column:record_id;size:32;index"`
	UserKey    string
	UserRoleID int
	UserName   string `sql:"type:varchar(20);not null;"`
	UserPass   string `sql:"type:varchar(50);not null;"`
	Phone      string `sql:"type:varchar(20);not null;"`
	Email      string `sql:"type:varchar(200);not null;"`
	UserType   int    `sql:"default:1;not null;"`
	VendorID   string `gorm:"column:vendor_id;size:32;index"`
	Status     int    `sql:"default:1;not null;"`
	Vendor     Vendor `gorm:"foreignkey:VendorID"`
}

// LoginRequest 登录请求
type LoginRequest struct {
	UserName string `json:"login_name" `
	Password string `json:"login_pass" `
}

// Reqrequest 注册请求
type Reqrequest struct {
	UserName   string `json:"username"`
	PassWord   string `json:"password" `
	Phone      string `json:"phone" `
	Email      string `json:"email" `
	VendorName string `json:"company"`
}

// ChangePassWordRequest 修改密码请求结构
type ChangePassWordRequest struct {
	OldPass string `json:"old_pass"` //base64加密后的字符串
	NewPass string `json:"new_pass"` //base64加密后的字符串
}

// Validate 验证
func (a *ChangePassWordRequest) Validate() error {
	if a.NewPass == "" || a.OldPass == "" {
		return errors.New("非法参数")
	}
	return nil
}

// Validate 验证
func (a *Reqrequest) Validate() error {
	if a.UserName == "" || a.PassWord == "" || a.Phone == "" || a.Email == "" || a.VendorName == "" {
		return errors.New("参数不能为空")
	}
	return nil
}

// Validate 验证
func (a *LoginRequest) Validate() error {
	if a.UserName == "" || a.Password == "" {
		return errors.New("参数不能为空")
	}
	return nil
}

// Validate 验证
func (a *User) Validate() error {
	if a.UserName == "" || a.UserPass == "" || a.Vendor.VendorName == "" {
		return errors.New("参数不能为空")
	}
	return nil
}
