package io.github.shirainbown.sharelink;

import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.ReactiveSettingFetcher;

/**
 * Typed access to this plugin's setting groups ({@code basic} and {@code emailVerify}).
 * Every getter falls back to built-in defaults and never returns {@link Mono#empty()}.
 */
@Component
@RequiredArgsConstructor
public class SharelinkSettingConfigGetter {

    private final ReactiveSettingFetcher settingFetcher;

    public Mono<BasicConfig> getBasicConfig() {
        return settingFetcher.fetch(BasicConfig.GROUP, BasicConfig.class)
            .defaultIfEmpty(new BasicConfig());
    }

    public Mono<EmailVerifyConfig> getEmailVerifyConfig() {
        return settingFetcher.fetch(EmailVerifyConfig.GROUP, EmailVerifyConfig.class)
            .defaultIfEmpty(new EmailVerifyConfig());
    }

    @Data
    public static class BasicConfig {
        public static final String GROUP = "basic";

        private int tokenTtlSeconds = 60;

        private int dedupeWindowMinutes = 10;
    }

    @Data
    public static class EmailVerifyConfig {
        public static final String GROUP = "emailVerify";

        private int codeExpireMinutes = 10;

        private int resendIntervalSeconds = 60;

        private int dailySendLimitPerEmail = 5;

        private int maxVerifyAttempts = 5;

        private int ipHourlySendLimit = 20;

        private boolean trustCommentVerified = true;
    }
}
