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

import com.atlassian.bitbucket.internal.key.ssh.dao.DelegatingSshKey;
import com.atlassian.bitbucket.ssh.SshKey;
import com.atlassian.bitbucket.user.ApplicationUser;
import net.java.ao.*;
import net.java.ao.schema.*;

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

@Preload
@Table(AoSshKeyV1.TABLE_NAME)
@Implementation(DelegatingSshKey.class)
public interface AoSshKeyV1 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 COLUMN_CREATOR_ID = "CREATOR_ID";

    String TABLE_NAME = "SSH_PUBLIC_KEY";

    int LENGTH_MD5 = 32;
    int LENGTH_LABEL = 255;

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

    @OneToMany(reverse = "getKey")
    AoSshAccessKeyV1[] getAccessEntries();

    @Nullable
    @Indexed
    @Accessor(COLUMN_CREATOR_ID)
    Integer getCreatorId();

    @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();

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

    //for updating
    @Mutator(COLUMN_USER_ID)
    void setUserId(Integer id);

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

    @Ignore
    ApplicationUser getUser();

    @Ignore
    PublicKey toPublicKey();
}
