package ch.unisg.tapas.auctionhouse.adapter.common.formats;

import ch.unisg.tapas.auctionhouse.domain.AuctionHouseDiscoveryInformation;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

public class AuctionHouseDiscoveryJsonRepresentation {
    public static final String MEDIA_TYPE = "application/auctionhousediscovery+json";

    @Getter @Setter
    private String auctionHouseUri;

    @Getter @Setter
    private String webSubUri;

    @Getter @Setter
    private List<String> taskTypes;

    @Getter @Setter
    private String timeStamp;

    @Getter @Setter
    private String groupName;

    public AuctionHouseDiscoveryJsonRepresentation() {}

    public AuctionHouseDiscoveryJsonRepresentation(AuctionHouseDiscoveryInformation auctionHouseDiscoveryInformation){
        this.auctionHouseUri = auctionHouseDiscoveryInformation.getAuctionHouseUri().getValue().toString();
        this.webSubUri = auctionHouseDiscoveryInformation.getWebSubUri().getValue().toString();
        this.taskTypes = auctionHouseDiscoveryInformation.getTaskTypes().getValue();
        this.timeStamp = auctionHouseDiscoveryInformation.getTimeStamp().getValue().toString();
        this.groupName = auctionHouseDiscoveryInformation.getGroupName().getValue();
    }

    public static String serialize(AuctionHouseDiscoveryInformation auctionHouseDiscoveryInformation) throws JsonProcessingException {
        AuctionHouseDiscoveryJsonRepresentation representation = new AuctionHouseDiscoveryJsonRepresentation(auctionHouseDiscoveryInformation);

        ObjectMapper mapper = new ObjectMapper();
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return mapper.writeValueAsString(representation);
    }
}
