package com.iqser.red.service.persistence.management.v1.processor.entity.configuration;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "color_configuration")
public class ColorsEntity {

    @Id
    @Column
    private String dossierTemplateId;

    @Column
    private String requestAddColor;
    @Column
    private String requestRemoveColor;
    @Column
    private String dictionaryRequestColor;
    @Column
    private String previewColor;
    @Column
    private String analysisColor;
    @Column
    private String updatedColor;
    @Column
    private String recommendationColor;
    @Column
    private String hintColor;
    @Column
    private String redactionColor;
    @Column
    private String ignoredHintColor;
    @Column
    private String skippedColor;
    @Column
    private String appliedRedactionColor;


    @PrePersist
    public void prePersist() {

        this.adjustColors();
    }


    private void adjustColors() {

        requestAddColor = setToLowerCase(requestAddColor);
        requestRemoveColor = setToLowerCase(requestRemoveColor);
        dictionaryRequestColor = setToLowerCase(dictionaryRequestColor);
        previewColor = setToLowerCase(previewColor);
        analysisColor = setToLowerCase(analysisColor);
        updatedColor = setToLowerCase(updatedColor);
        recommendationColor = setToLowerCase(recommendationColor);
        hintColor = setToLowerCase(hintColor);
        ignoredHintColor = setToLowerCase(ignoredHintColor);
        skippedColor = setToLowerCase(skippedColor);
        appliedRedactionColor = setToLowerCase(appliedRedactionColor);
    }


    private String setToLowerCase(String color) {

        if (color == null) {
            return null;
        }
        return color.toLowerCase();
    }


    @PreUpdate
    public void preUpdate() {

        this.adjustColors();
    }

}
