package camel_oil

import (
	"context"

	"github.com/gogf/gf/v2/errors/gcode"
	v1 "kami/api/camel_oil/v1"
	"kami/internal/errHandler"
	"kami/internal/service"
)

func (c *ControllerV1) DeleteExpiredAccounts(ctx context.Context, req *v1.DeleteExpiredAccountsReq) (res *v1.DeleteExpiredAccountsRes, err error) {
	// 验证管理员权限 - 只有管理员才能执行批量删除操作
	_, err = service.SysAuth().LoginOnlyIFrame(ctx)
	if err != nil {
		err = errHandler.WrapError(ctx, gcode.CodeNotAuthorized, err, "需要管理员权限才能执行此操作")
		return
	}

	// 调用服务层方法删除过期账号
	deletedCount, err := service.CamelOil().DeleteAllExpiredAccounts(ctx)
	if err != nil {
		return nil, err
	}

	return &v1.DeleteExpiredAccountsRes{
		Message:      "批量删除过期账号完成",
		DeletedCount: deletedCount,
	}, nil
}
