package taskqueue

import (
	"fmt"
	"time"

	"github.com/tidbcloud/metrics-integration/pipeline/internal/otel_collector/extension/taskqueue/persistent"
)

type Config struct {
	Interval  string            `mapstructure:"interval"`
	StartTs   int64             `mapstructure:"start_ts"`
	EndTs     int64             `mapstructure:"end_ts"`
	BatchMode bool              `mapstructure:"batch_mode"`
	BatchSize string            `mapstructure:"batch_size"`
	Timeout   string            `mapstructure:"timeout"`
	Persist   persistent.Config `mapstructure:"persist"`
}

func (cfg *Config) Validate() error {
	_, err := time.ParseDuration(cfg.Interval)
	if err != nil {
		return fmt.Errorf("parse interval failed: %w", err)
	}

	_, err = time.ParseDuration(cfg.Timeout)
	if err != nil {
		return fmt.Errorf("parse timeout failed: %w", err)
	}

	_, err = time.ParseDuration(cfg.BatchSize)
	if err != nil {
		return fmt.Errorf("parse batch failed: %w", err)
	}

	return nil
}
