package de.oaa.xxx.games.chastity.community;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.UUID;

import de.oaa.xxx.games.chastity.common.Verification;
import de.oaa.xxx.games.chastity.common.VerificationCommonDTO;
import jakarta.persistence.Column;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@DiscriminatorValue("VERIFICATION")
public class CommunityVerificationEntity extends BaseCommunityDisplayEntity implements Verification {

	@Column(nullable = false)
	private String code;
	@Column(columnDefinition = "MEDIUMBLOB")
	private byte[] image;
	@Column
	private int countUpvotes;
	@Column
	private int countDownvotes;
	
	@Override
	public String getType() { return "VERIFICATION"; }

	public CommunityVerificationDTO toVerification(boolean isOwnLock, Boolean myVote) {
		return new CommunityVerificationDTO(getDisplayId(), code, getCreatedAt(), image, new ArrayList<>(), countUpvotes, countDownvotes, isOwnLock, myVote);
	}
	
	@Override
	public LocalDate getVerificationDate() {
		return getCreatedAt().toLocalDate();
	}
	
	@Override
	public boolean isValid() {
		return countUpvotes > countDownvotes;
	}
	
	@Override
	public VerificationCommonDTO toCommonVerification() {
		return new VerificationCommonDTO(getDisplayId(), getLockId(), code, getCreatedAt(), image, getLockeeId(),
				getKeyholderId());
	}

	@Override
	public UUID getId() {
		return getDisplayId();
	}

	@Override
	public void setId(UUID id) {
		setDisplayId(id);
	}
}
