package com.vaessl.app.connection;

import java.time.Instant;

import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.Getter;
import lombok.Setter;

@Entity
@DiscriminatorValue("HOMEBOX")
@Getter
@Setter
public class HomeboxConnectionEntity extends ConnectionEntity {

    private String token;
    private String attachmentToken;
    private Instant expiresAt;

    public static HomeboxConnectionEntity from(ConnectionRequest request, ConnectionResponse response) {

        HomeboxConnectionEntity he = new HomeboxConnectionEntity();

        he.setAppUrl(request.appUrl());
        he.setUsername(request.username());
        he.setToken(response.token());
        he.setAttachmentToken(response.getExtraVar("attachmentToken"));
        he.setExpiresAt(response.expiresAt());

        return he;
    }
}
