package service

import (
	"github.com/linmadan/egglib-go/core/application"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/dto"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/users/query"

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

// 用户信息
type UsersService struct {
}

// 获取公司用户信息
func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.CompanyUserGetQuery) (interface{}, error) {

	return nil, nil
}

// 创建公司用户信息
func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.CompanyUserAddCommand) (interface{}, error) {

	return nil, nil
}

// 启用禁用公司用户信息
func (usersService *UsersService) CompanyUserEnable(companyUserEnableCommand *command.CompanyUserEnableCommand) (interface{}, error) {

	return nil, nil
}

// 返回公司用户信息列表
func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.CompanyUserListQuery) (int64, interface{}, error) {
	creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(0, 0, 0)
	result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
		Offset:         (companyUserListQuery.PageNumber - 1) * companyUserListQuery.PageSize,
		Limit:          companyUserListQuery.PageSize,
		CompanyId:      companyUserListQuery.CompanyId,
		OrganizationId: 0,
		DepartmentId:   0,
		UserName:       companyUserListQuery.UserName,
		DepName:        companyUserListQuery.DepartmentName,
		Phone:          "",
	})

	if err != nil {
		return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
	}
	//数据转换
	cnt := int64(result.Count)
	var (
		listData []dto.UserListItem
		item     dto.UserListItem
	)
	for _, v := range result.Users {
		item = dto.UserListItem{
			DepName:      v.Ext.DepName,
			OrgName:      v.Ext.OrgName,
			Phone:        v.Ext.Phone,
			EnableStatus: v.EnableStatus,
			UserCode:     v.UserCode,
			UserId:       int64(v.UserID),
			UserName:     v.UserName,
		}
		listData = append(listData, item)
	}
	return cnt, listData, nil
}

// 批量重置密码
func (usersService *UsersService) CompanyUserResetPassword(companyUserResetPasswordCommand *command.CompanyUserResetPasswordCommand) (interface{}, error) {

	return nil, nil
}

// 更新公司用户信息
func (usersService *UsersService) CompanyUserUpdate(companyUserUpdateCommand *command.CompanyUserUpdateCommand) (interface{}, error) {

	return nil, nil
}

// 创建共创用户信息
func (usersService *UsersService) CooperationUserAdd(cooperationUserAddCommand *command.CooperationUserAddCommand) (interface{}, error) {

	return nil, nil
}

// 启用禁用共创用户信息
func (usersService *UsersService) CooperationUserEnable(cooperationUserEnableCommand *command.CooperationUserEnableCommand) (interface{}, error) {
	return nil, nil
}

// 获取共创用户信息
func (usersService *UsersService) CooperationUserGet(cooperationUserGetQuery *query.CooperationUserGetQuery) (interface{}, error) {

	return nil, nil
}

// 返回共创用户信息列表
func (usersService *UsersService) CooperationUserList(cooperationUserListQuery *query.CooperationUserListQuery) (interface{}, error) {

	return nil, nil
}

// 批量重置密码
func (usersService *UsersService) CooperationUserResetPassword(cooperationUserResetPasswordCommand *command.CooperationUserResetPasswordCommand) (interface{}, error) {

	return nil, nil
}

// 编辑共创用户信息
func (usersService *UsersService) CooperationUserUpdate(cooperationUserUpdateCommand *command.CooperationUserUpdateCommand) (interface{}, error) {

	return nil, nil
}

func NewUsersService(options map[string]interface{}) *UsersService {
	newUsersService := &UsersService{}
	return newUsersService
}