package de.tsschulz.tt_tagebuch.shared.api.models

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonObject

@Serializable
data class LeaguePlayerStatDto(
    val memberId: Int,
    val firstName: String = "",
    val lastName: String = "",
    val totalSeason: Int = 0,
    val totalFirstHalf: Int = 0,
    val totalSecondHalf: Int = 0,
)

@Serializable
data class ClubTeamLineupRowDto(
    val id: Int? = null,
    val clubTeamId: Int? = null,
    val memberId: Int,
    val lineupHalf: String? = null,
    val position: Int = 0,
    val member: Member? = null,
)

@Serializable
data class TeamLineupAssignmentItem(
    val memberId: Int,
    val position: Int,
)

@Serializable
data class TeamLineupUpdateBody(
    val assignments: List<TeamLineupAssignmentItem>,
    val lineupHalf: String,
)

/** Zeile aus `GET /api/clubmembers/play-interest/:clubId` (Sequelize `toJSON`). */
@Serializable
data class MemberPlayInterestRowDto(
    val memberId: Int,
    val seasonId: Int? = null,
    val lineupHalf: String? = null,
    val interested: Boolean? = null,
)

@Serializable
data class MemberPlayInterestSetBody(
    val memberId: Int,
    val seasonId: Int,
    val lineupHalf: String,
    val interested: Boolean = true,
)

@Serializable
data class TeamDocumentDto(
    val id: Int,
    val fileName: String = "",
    val originalFileName: String = "",
    val documentType: String = "",
    val clubTeamId: Int? = null,
    val createdAt: String? = null,
    val mimeType: String? = null,
)

@Serializable
data class TeamDocumentParseResultDto(
    val matchesFound: Int = 0,
)

@Serializable
data class TeamDocumentSaveResultDto(
    val created: Int = 0,
    val updated: Int = 0,
)

@Serializable
data class TeamDocumentParseEnvelopeDto(
    val parseResult: TeamDocumentParseResultDto? = null,
    val saveResult: TeamDocumentSaveResultDto? = null,
)

@Serializable
data class SchedulerLastExecutionsEnvelopeDto(
    val success: Boolean = false,
    val data: SchedulerLastExecutionsDataDto? = null,
)

@Serializable
data class SchedulerLastExecutionsDataDto(
    @SerialName("rating_updates")
    val ratingUpdates: SchedulerJobBlockDto? = null,
    @SerialName("match_results")
    val matchResults: SchedulerJobBlockDto? = null,
)

@Serializable
data class SchedulerJobBlockDto(
    val lastRun: String? = null,
    val success: Boolean? = null,
    val executionTime: Int? = null,
    val updatedCount: Int? = null,
    val fetchedCount: Int? = null,
    val errorMessage: String? = null,
    val teamDetails: List<SchedulerTeamDetailDto> = emptyList(),
)

@Serializable
data class SchedulerTeamDetailDto(
    val clubTeamId: Int = 0,
    val teamName: String? = null,
    val success: Boolean = false,
    val lastRun: String? = null,
)

@Serializable
data class MyTtParseUrlBody(val url: String)

@Serializable
data class MyTtConfigureTeamBody(
    val url: String,
    val clubTeamId: Int,
    val createLeague: Boolean? = null,
    val createSeason: Boolean? = null,
)

@Serializable
data class MyTtConfigureLeagueBody(
    val url: String,
    val createSeason: Boolean? = null,
)

@Serializable
data class MyTtFetchTeamDataBody(val clubTeamId: Int)

@Serializable
data class MyTtFetchJobStartDto(
    val success: Boolean = false,
    val jobId: String? = null,
    val status: String? = null,
)

@Serializable
data class MyTtFetchJobEnvelopeDto(
    val success: Boolean = false,
    val job: MyTtFetchJobDto? = null,
)

@Serializable
data class MyTtFetchJobDto(
    val jobId: String? = null,
    val status: String? = null,
    val result: JsonObject? = null,
    val error: String? = null,
)
