package models

import "time"

// LdapServer LDAP 服务配置表
type LdapServer struct {
	Id int `orm:"pk;auto" json:"id"`
	// 用户账号,唯一标识, Uid
	Uid           string `orm:"size(100)" json:"uid"`
	Name          string `orm:"size(255)" json:"name"`
	Key           string `orm:"unique" json:"key"`
	Url           string `json:"url"`
	Active        bool   `json:"active"`   // 是否激活可用
	UserName      string `json:"userName"` // 直接存储JSON数据,数组格式,多个
	Password      string `json:"password"`
	BaseDN        string `orm:"size(255);column(base_dn)" json:"baseDN"`
	Filter        string `orm:"size(255)" json:"filter"`
	Remark        string `json:"remark"`
	OrganizeClass string `orm:"size(255)" json:"organizeClass"` // 组织的objectClass
}

// LdapUser User 用户表
// https://blog.csdn.net/wzjking0929/article/details/81153206
type LdapUser struct {
	Id  int    `orm:"pk;auto" json:"id"`
	Uid string `json:"uid"`
	// 用户账号,唯一标识, Uid
	Account      string    `orm:"unique" json:"account"` // 即DN,eg. cn=test,dc=xxxx,dc=cn
	UserName     string    `json:"userName"`
	Mail         string    `json:"mail"`
	DN           string    `orm:"unique;column(db)" json:"dn"`
	Attributes   string    `orm:"null;type(text)" json:"attributes"` // 直接存储JSON数据,数组格式,多个
	SignType     string    `json:"signType"`                         // 密码加密方式
	Password     string    `json:"password"`
	Remark       string    `json:"remark"`
	ServerKey    string    `json:"serverKey"`
	LastSyncDate time.Time `orm:"null;type(datetime)" json:"lastSyncDate"` // 最后一次同步的时间
	Organize     string    `orm:"default('');type(text)" json:"organize"`
}

type LdapOrganize struct {
	Id          int    `orm:"pk;auto" json:"id"`
	ServerKey   string `orm:"size(255)" json:"serverKey"`
	DN          string `orm:"unique;column(dn)" json:"dn"`
	ObjectClass string `orm:"size(255)" json:"objectClass"`
	Name        string `orm:"size(255)" json:"name"`
	Remark      string `orm:"null;type(text)" json:"remark"`
}

func (s *LdapServer) UniqueClone() (*LdapServer, string) {
	return &LdapServer{
		Url: s.Url,
	}, "Url"
}

func (s *LdapUser) UniqueClone() (*LdapUser, string) {
	return &LdapUser{
		DN:      s.DN,
		Account: s.Account,
	}, "DN"
}

func (s *LdapOrganize) UniqueClone() (*LdapOrganize, string) {
	return &LdapOrganize{
		DN: s.DN,
	}, "DN"
}