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 downloadable resource registered from an attachment. The {@code spec.slug} is the
 * public URL identifier ({@code /download/{slug}}) and carries a unique index.
 */
@GVK(group = "sharelink.halo.run", version = "v1alpha1", kind = "DownloadResource",
    plural = "downloadresources", singular = "downloadresource")
@Data
@EqualsAndHashCode(callSuper = true)
public class DownloadResource extends AbstractExtension {

    private Spec spec;

    private Status status;

    @Data
    public static class Spec {

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

        private String displayName;

        private String description;

        /**
         * Metadata name of the associated {@code Attachment} extension.
         */
        private String attachmentName;

        private boolean requireEmailVerify;

        private boolean enabled;
    }

    @Data
    public static class Status {

        /**
         * Redundant download counter; the authoritative source is DownloadRecord.
         */
        private long downloadCount;
    }
}
