ManifestReloadTaskModel.kt

/*
  Copyright (C) 2026 Sber

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

package org.archtool.data.model

import java.io.Serializable

data class ManifestReloadTaskModel(
    var currentStep: Step = Step.START_GAS_UPDATE,
    var errorMessage: String? = null,
    var backend: String,
    var secret: String? = null,
    var reloadRoot: Boolean? = null,
    var mode: String? = null,
    var aliases: List<String>? = null,
    var scheduleId: String? = null,
    // Поля выше — первый запрос прогона. Здесь только запросы сверх него: так данные задачи остаются
    // совместимыми с версией без очереди в обе стороны.
    var additionalRequests: List<ReloadRequestModel> = emptyList(),
    // Базы версий загрузки seaf-core (ERA-3627). null — CHECK_SEPORTAL проверяет завершение по /health: core не
    // вернул версии или прогон начат версией без них. Прежняя версия при откате поле пропускает.
    var loadBases: LoadBasesModel? = null
) : Serializable {
    enum class Step {
        START_GAS_UPDATE, CHECK_GAS, START_SEPORTAL_RELOAD, CHECK_SEPORTAL
    }

    fun requests(): List<ReloadRequestModel> =
        listOf(ReloadRequestModel(secret, reloadRoot, mode, aliases, scheduleId)) + additionalRequests

    companion object {
        fun of(backend: String, requests: List<ReloadRequestModel>): ManifestReloadTaskModel {
            val first = requests.first()
            return ManifestReloadTaskModel(
                backend = backend,
                secret = first.secret,
                reloadRoot = first.reloadRoot,
                mode = first.mode,
                aliases = first.aliases,
                scheduleId = first.scheduleId,
                additionalRequests = requests.drop(1)
            )
        }
    }
}