package com.caliverse.admin.dynamodb.repository.Impl;

import com.caliverse.admin.dynamodb.domain.atrrib.MoneyAttrib;
import com.caliverse.admin.dynamodb.domain.doc.MoneyDoc;
import com.caliverse.admin.dynamodb.repository.BaseDynamoDBRepository;
import com.caliverse.admin.dynamodb.repository.MoneyRepository;
import com.caliverse.admin.dynamodb.service.DynamoDBOperations;
import com.caliverse.admin.global.common.constants.DynamoDBConstants;
import com.caliverse.admin.history.service.DynamodbHistoryLogService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import software.amazon.awssdk.enhanced.dynamodb.Key;

@Component
@Slf4j
public class MoneyRepositoryImpl extends BaseDynamoDBRepository<MoneyDoc> implements MoneyRepository {
    public MoneyRepositoryImpl(DynamoDBOperations operations, DynamodbHistoryLogService dynamodbHistoryLogService, ObjectMapper objectMapper) {
        super(operations, MoneyDoc.class, dynamodbHistoryLogService, objectMapper);
    }

    public MoneyAttrib findAttrib(String guid) {
        Key key = Key.builder()
                .partitionValue(String.format("%s%s",DynamoDBConstants.PK_KEY_MONEY, guid))
                .sortValue(DynamoDBConstants.EMPTY)
                .build();

        MoneyDoc doc = findById(key);
        return doc != null ? doc.getAttribValue() : null;
    }

}
