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

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.amazon.AmazonChartTrackEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
public class AmazonChartPosition extends AbstractChartPosition {

    @JsonProperty("total_days")
    private Integer totalDays;

    public static AmazonChartPosition of(AmazonChartTrackEntity entity) {
        if (entity == null) {
            return null;
        }
        return AmazonChartPosition.builder()
            .current(entity.getCurrentPosition())
            .date(entity.getDate())
            .dateGap(JsonNullable.of(entity.getDateGap()))
            .isEntry(entity.getIsChartEntry())
            .isReentry(entity.getIsChartReentry())
            .isExit(entity.getIsExit())
            .previousDate(JsonNullable.of(entity.getPrevChartDate()))
            .previousPosition(entity.getPreviousPosition())
            .totalDays(entity.getTotalDays())
            .trend(entity.getTrend()).build();
    }

}