package dto

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
	"strings"
)

type UserBaseDto struct {
	// 用户基础数据id
	UserBaseId int `json:"userBaseId,omitempty"`
	//姓名
	UserName string `json:"userName"`
	// 账号
	Account string `json:"account"`
	// 用户关联的组织
	Organizations string `json:"organizations"`
	// 账号状态 1:正常 2.禁用 3:注销
	Status int `json:"status,omitempty"`
	// 推荐人
	Referer string `json:"referer"`
	// 创建时间
	RegistrationDate string `json:"registrationDate,omitempty"`
	// 最后登录时间
	LastLogIn string `json:"lastLogIn"`
}

func (dto *UserBaseDto) LoadDto(detail allied_creation_user.UserBaseDetail) {
	dto.UserBaseId = detail.UserBaseId
	dto.UserName = detail.UserInfo.UserName
	dto.Account = detail.UserInfo.Phone
	dto.Status = detail.Status
	dto.Referer = detail.Referer
	dto.RegistrationDate = detail.RegistrationDate
	dto.LastLogIn = detail.LastLogIn
	var organizations []string
	for i := range detail.UserOrg {
		if len(detail.UserOrg[i].OrgName) == 0 {
			continue
		}
		organizations = append(organizations, detail.UserOrg[i].OrgName)
	}
	dto.Organizations = strings.Join(organizations, ",")
}