package documents

import (
	"strings"

	"github.com/tech/sendico/billing/documents/internal/content"
	"github.com/tech/sendico/billing/documents/internal/docstore"
	"github.com/tech/sendico/billing/documents/renderer"
)

// Config holds document service settings loaded from YAML.
type Config struct {
	Issuer     IssuerConfig     `yaml:"issuer"`
	Templates  TemplateConfig   `yaml:"templates"`
	Protection ProtectionConfig `yaml:"protection"`
	Storage    docstore.Config  `yaml:"storage"`
}

// IssuerConfig defines issuer settings that are environment-specific.
type IssuerConfig struct {
	LogoPath string `yaml:"logo_path"`
}

// TemplateConfig defines document template locations.
type TemplateConfig struct {
	AcceptancePath string `yaml:"acceptance_path"`
}

// ProtectionConfig configures PDF protection.
type ProtectionConfig struct {
	OwnerPassword string `yaml:"owner_password"`
}

func (c Config) IssuerDetails() renderer.Issuer {
	return renderer.Issuer{
		LegalName:    content.IssuerLegalName,
		LegalAddress: content.IssuerLegalAddress,
		LogoPath:     c.Issuer.LogoPath,
	}
}

func (c Config) AcceptanceTemplatePath() string {
	if strings.TrimSpace(c.Templates.AcceptancePath) == "" {
		return "templates/acceptance.tpl"
	}

	return c.Templates.AcceptancePath
}
