package org.octopus.internal.common.models

import com.fasterxml.jackson.annotation.JsonGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import io.swagger.v3.oas.annotations.media.Schema
import org.octopus.internal.common.enums.EEntryType
import java.time.Month
import java.util.*

data class Entry(
    @field:Schema(description = "The id of the entry in the DB")
    var id: Long?,
    @field:Schema(description = "The name of the entry (between 1 and 50 characters long).")
    val name: String,
    @field:Schema(description = "The type of entry (INCOME, OUTCOME, INVESTMENT).")
    val type: EEntryType,
    @field:Schema(description = "The amount of the entry (greater than 0.00).")
    val amount: Double,
    @field:Schema(description = "IF NOT recurrent: when is the entry being counted.")
    val fixedDate: Date? = null,
    @field:Schema(description = "IF recurrent: must be true")
    val recurrent: Boolean? = false,
    @field:Schema(description = "IF recurrent: list of month in which the event is repeated (1=JAN, 12=DEC)")
    @get:JsonIgnore
    val recurrentMonths: List<Month>? = mutableListOf(),
    @field:Schema(description = "IF recurrent: starting date of the repetition")
    val startDate: Date? = null,
    @field:Schema(description = "IF recurrent: ending date of the repetition")
    val endDate: Date? = null,
    @field:Schema(description = "Color of the entry in the UI")
    val color: String
){

    @JsonGetter("recurrentMonths")
    fun getRecurrentMonthsAsInts(): List<Int>? {
        return this.recurrentMonths?.map { it.value }
    }
}