package migrate

// migration for jump service to support multi jumps.
// var _ = AddMigrateRecord(
// 	"202410171400",
// 	func(raw *gorm.DB) error {
// 		err := raw.AutoMigrate(
// 			&jmpmod.Authorization{}, &jmpmod.Jump{},
// 		)
// 		if err != nil {
// 			return err
// 		}

// 		db := db.NewProvider(raw)
// 		jmpRepo := repo.NewJumpRepo(db)

// 		// migrate auth to jumps
// 		return db.Transaction(context.Background(), func(ctx context.Context) error {
// 			curAuths, err := jmpRepo.ListAuthorizations(ctx)
// 			if err != nil {
// 				return err
// 			}

// 			for _, curAuth := range curAuths {
// 				if len(curAuth.Jumps) != 0 {
// 					continue
// 				}

// 				// generate jump
// 				jump := &jmpent.Jump{
// 					ID:            0,
// 					Destination:   &jmpent.DestinationUnion{},
// 					TokenExpireAt: curAuth.TokenExpireAt,
// 				}
// 				switch curAuth.Plane {
// 				case "data_plane":
// 					if curAuth.ClusterDeployType == "dedicated" {
// 						clusterID, err := strconv.ParseUint(curAuth.ClusterID, 10, 64)
// 						if err != nil {
// 							return err
// 						}

// 						jump.Destination.DedicatedCluster = &jmpent.DestinationDedicatedCluster{
// 							ClusterID: clusterID,
// 						}
// 					}
// 					if curAuth.ClusterDeployType == "serverless" {
// 						jump.Destination.ServerlessCluster = &jmpent.DestinationServerlessCluster{
// 							Name: curAuth.ClusterID,
// 						}
// 					}
// 				case "control_plane":
// 					jump.Destination.ControlPlane = &jmpent.DestinationControlPlane{
// 						Name: curAuth.ClusterID,
// 					}
// 				}

// 				// update auth
// 				err := jmpRepo.PatchAuthorization(ctx, curAuth, func(current *jmpent.Authorization) error {
// 					curAuth.Jumps = []*jmpent.Jump{jump}
// 					return nil
// 				})
// 				if err != nil {
// 					return err
// 				}
// 			}

// 			return nil
// 		})

// 	},
// )
