package org.mercury_im.messenger.data.model;

import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.jivesoftware.smackx.ox.store.definition.OpenPgpTrustStore;
import org.jxmpp.jid.EntityBareJid;
import org.mercury_im.messenger.data.converter.Base64PGPPublicKeyRingConverter;
import org.mercury_im.messenger.data.converter.EntityBareJidConverter;
import org.mercury_im.messenger.data.converter.OpenPgpV4FingerprintConverter;
import org.pgpainless.key.OpenPgpV4Fingerprint;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import io.requery.CascadeAction;
import io.requery.Column;
import io.requery.Convert;
import io.requery.Entity;
import io.requery.Index;
import io.requery.Key;
import io.requery.OneToMany;
import io.requery.Table;
import io.requery.converter.UUIDConverter;
import lombok.ToString;

@Table(name = "ikey_record", uniqueIndexes = "unique_ikey_record")
@Entity
@ToString
public class AbstractIkeyRecordModel {

    @Key
    @Convert(UUIDConverter.class)
    UUID id;

    @Index("unique_ikey_record")
    @Column
    @Convert(UUIDConverter.class)
    UUID accountId;

    @Index("unique_ikey_record")
    @Column(name = "jid")
    @Convert(EntityBareJidConverter.class)
    EntityBareJid jid;

    @Column(name = "contender")
    boolean contender;

    @Column(name = "\"timestamp\"")
    Date timestamp;

    @OneToMany(mappedBy = "record", cascade = {CascadeAction.DELETE, CascadeAction.SAVE})
    @Column
    List<IkeySubordinateModel> subordinates;

    @Column(name = "superordinate")
    @Convert(Base64PGPPublicKeyRingConverter.class)
    PGPPublicKeyRing superordinate;

    @Index("unique_ikey_record")
    @Column(name = "fingerprint")
    @Convert(OpenPgpV4FingerprintConverter.class)
    OpenPgpV4Fingerprint fingerprint;

    @Column
    OpenPgpTrustStore.Trust trust;
}
