package com.atlassian.bitbucket.internal.key.ssh.dao;

import com.atlassian.bitbucket.ssh.SshKey;
import com.atlassian.bitbucket.user.ApplicationUser;
import net.java.ao.Accessor;
import net.java.ao.Implementation;
import net.java.ao.Preload;
import net.java.ao.RawEntity;
import net.java.ao.schema.*;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.security.PublicKey;

@Preload
@Table(AoSshKey.TABLE_NAME)
@Implementation(DelegatingSshKey.class)
public interface AoSshKey extends RawEntity<Integer>, SshKey {
    String COLUMN_ID = "ENTITY_ID";
    String COLUMN_USER_ID = "USER_ID";
    String COLUMN_KEY_TEXT = "KEY_TEXT";
    String COLUMN_KEY_MD5 = "KEY_MD5";
    String COLUMN_LABEL = "LABEL";

    String TABLE_NAME = "SSH_PUBLIC_KEY";

    int LENGTH_MD5 = 32;
    int LENGTH_LABEL = 255;

    @AutoIncrement
    @NotNull
    @PrimaryKey(COLUMN_ID)
    Integer getId();

    @NotNull
    @Indexed
    @StringLength(LENGTH_MD5)
    @Accessor(COLUMN_KEY_MD5)
    String getMD5();

    @Nullable
    @StringLength(LENGTH_LABEL)
    @Accessor(COLUMN_LABEL)
    String getLabel();

    @NotNull
    @StringLength(StringLength.UNLIMITED)
    @Accessor(COLUMN_KEY_TEXT)
    String getText();

    @NotNull
    @Indexed
    @Accessor(COLUMN_USER_ID)
    Integer getUserId();

    // methods that we want on the interface, but should be ignored by AO
    @Ignore
    void initialize(ApplicationUser owner);

    @Nullable
    @Ignore
    ApplicationUser getUser();

    @Nonnull
    @Ignore
    PublicKey toPublicKey();
}
