package com.atlassian.bitbucket.internal.mirroring.upstream.dao;

import com.atlassian.bitbucket.internal.mirroring.MirroringRequest;
import com.atlassian.bitbucket.internal.mirroring.MirroringRequestState;
import com.atlassian.bitbucket.user.ApplicationUser;
import net.java.ao.*;
import net.java.ao.schema.*;

import javax.annotation.Nonnull;
import java.util.Date;

import static com.atlassian.bitbucket.internal.mirroring.MirroringConstants.*;
import static com.atlassian.bitbucket.internal.mirroring.dao.AoConstants.*;

/**
 * AO entity for modelling the details and state of requests by servers to act as a mirror
 */
@Table(AoMirroringRequest.TABLE_NAME)
@Preload
@Implementation(DelegatingMirroringRequest.class)
public interface AoMirroringRequest extends RawEntity<Integer>, MirroringRequest {
    String TABLE_NAME = "MIRRORING_REQUEST";

    String[] ALL_COLUMNS = {
        ID_COLUMN,
        DESCRIPTOR_URL_COLUMN,
        BASE_URL_COLUMN,
        MIRROR_ID_COLUMN,
        MIRROR_NAME_COLUMN,
        PRODUCT_TYPE_COLUMN,
        PRODUCT_VERSION_COLUMN,
        STATE_COLUMN,
        CREATED_DATE_COLUMN,
        RESOLVED_DATE_COLUMN,
        RESOLVER_USER_ID_COLUMN,
    };

    @NotNull
    @Accessor(BASE_URL_COLUMN)
    @StringLength(MAX_BASE_URL_LENGTH)
    String getBaseUrl();

    @NotNull
    @Override
    @Accessor(CREATED_DATE_COLUMN)
    Date getCreatedDate();

    @NotNull
    @Accessor(DESCRIPTOR_URL_COLUMN)
    @StringLength(MAX_DESCRIPTOR_LENGTH)
    String getDescriptorUrl();

    @AutoIncrement
    @PrimaryKey(ID_COLUMN)
    @Override
    Integer getId();

    @Override
    @Indexed
    @NotNull
    @Accessor(MIRROR_ID_COLUMN)
    @StringLength(MAX_MIRROR_ID_LENGTH)
    String getMirrorId();

    @Override
    @NotNull
    @Accessor(MIRROR_NAME_COLUMN)
    @StringLength(MAX_MIRROR_NAME_LENGTH)
    String getMirrorName();

    @Override
    @NotNull
    @Accessor(PRODUCT_TYPE_COLUMN)
    @StringLength(MAX_PRODUCT_TYPE_LENGTH)
    String getProductType();

    @Override
    @NotNull
    @Accessor(PRODUCT_VERSION_COLUMN)
    @StringLength(MAX_PRODUCT_VERSION_LENGTH)
    String getProductVersion();

    @Override
    @Accessor(RESOLVED_DATE_COLUMN)
    Date getResolvedDate();

    @Accessor(RESOLVER_USER_ID_COLUMN)
    Integer getResolverId();

    @NotNull
    @Override
    @Indexed
    @Accessor(STATE_COLUMN)
    MirroringRequestState getState();

    @Ignore
    ApplicationUser getResolver();

    @Ignore
    void initResolver(@Nonnull ApplicationUser user);

    @Mutator(STATE_COLUMN)
    void setState(@Nonnull MirroringRequestState state);

    @Mutator(RESOLVED_DATE_COLUMN)
    void setResolvedDate(@Nonnull Date resolvedDate);

    @Mutator(RESOLVER_USER_ID_COLUMN)
    void setResolverId(int userId);
}
