package com.alterdekim.game.entity;

import com.alterdekim.game.controller.result.api.ApiResult;
import com.alterdekim.game.controller.result.api.PreloaderResult;
import com.alterdekim.game.controller.result.api.PromotionResult;
import com.alterdekim.game.xml.NumericBooleanSerializer;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name="promotions")
@JsonRootName(value = "i")
public class Promotion implements ApiResult {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @JsonIgnore
    private Long id;

    @JacksonXmlProperty(isAttribute = true, localName = "MRId")
    @Column(nullable = false)
    private Integer mrId;

    @JacksonXmlProperty(isAttribute = true, localName = "State")
    @Column(nullable = false)
    private String state;

    @JsonIgnore
    @Column(nullable = false)
    private Boolean isSelected;

    public Promotion(Integer mrId, String state, Boolean isSelected) {
        this.mrId = mrId;
        this.state = state;
        this.isSelected = isSelected;
    }

    @Override
    public PromotionResult toAPIResult() {
        return new PromotionResult(this.id, this.mrId, this.state, this.isSelected);
    }
}