package io.delphiplatform.api.v3.model.shazam;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.openapitools.jackson.nullable.JsonNullable;

import io.delphiplatform.api.v3.model.AbstractChartPosition;
import io.delphiplatform.api.v3.rdb.entity.shazam.FactShazamChartEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

/**
 * ShazamChartPosition
 */
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class ShazamChartPosition extends AbstractChartPosition {

    @JsonProperty("total_days")
    private Integer totalDays;

    public static ShazamChartPosition of(FactShazamChartEntity entity) {
        if (entity == null) {
            return null;
        }
        return ShazamChartPosition.builder()
            .current(entity.getLatestPosition())
            .date(entity.getDate())
            .dateGap(JsonNullable.of(entity.getDateGap()))
            .isEntry(entity.getIsEntry())
            .isReentry(entity.getIsReentry())
            .isExit(entity.getIsExit())
            .previousDate(JsonNullable.of(entity.getPreviousDate()))
            .previousPosition(entity.getPreviousPosition())
            .totalDays(entity.getOnChartDays())
            .trend(entity.getTrend()).build();
    }

}

