package io.github.shirainbown.sharelink.model;

import lombok.Data;
import lombok.EqualsAndHashCode;
import run.halo.app.extension.AbstractExtension;
import run.halo.app.extension.GVK;

/**
 * A hyperlink protected behind a gate page. The visitor opens {@code /link/{slug}},
 * passes the (optional) email verification, and is redirected to {@code spec.targetUrl}
 * after a one-time token is consumed. The {@code spec.slug} is the public URL identifier
 * and carries a unique index.
 */
@GVK(group = "sharelink.halo.run", version = "v1alpha1", kind = "ProtectedLink",
    plural = "protectedlinks", singular = "protectedlink")
@Data
@EqualsAndHashCode(callSuper = true)
public class ProtectedLink extends AbstractExtension {

    private Spec spec;

    private Status status;

    @Data
    public static class Spec {

        /**
         * URL identifier of the link, unique across all links. Matches
         * {@code [a-z0-9][a-z0-9-]{0,63}}.
         */
        private String slug;

        private String displayName;

        private String description;

        /**
         * The destination the visitor is redirected to after verification (http/https).
         */
        private String targetUrl;

        private boolean requireEmailVerify;

        private boolean enabled;
    }

    @Data
    public static class Status {

        /**
         * Redundant visit counter; the authoritative source is LinkVisitRecord.
         */
        private long visitCount;
    }
}
