"""Business facts — the real, human-confirmed information that lets the
auto-fixer safely turn 'needs manual content work' into 'auto-fixable'.

The tool will never invent a phone number, a review, a stat, or an FAQ
answer. Every field here starts empty. Once YOU fill in something real
(from the dashboard's Business Facts tab, or by editing this file), the
matching fixer in remediate.py turns it into proper schema/links
automatically on your next approval — no manual HTML editing needed.
"""
from __future__ import annotations
from pathlib import Path

import yaml

APP_DIR = Path(__file__).parent.parent
BF_CFG = APP_DIR / "business_facts.yaml"

DEFAULT_CFG = """\
# Real facts about your business only — leave anything blank you can't
# personally vouch for. The tool never invents values here; it only turns
# what you provide into proper links/schema automatically once approved.

phone: ""              # e.g. "+91 98765 43210" — must be a real, working number
email: ""              # e.g. "you@yourbusiness.com"

# One real, true sentence — a stat you can stand behind, e.g.
# "400+ clients served since 2018". Published on the page exactly as typed.
stats_blurb: ""

# Only include testimonials that are REAL and already visible somewhere
# on your site — this makes the structured data match real content, which
# is what search engines require. Up to 3.
testimonials: []
#  - name: "Jane Doe"
#    org: "Acme Ltd"
#    quote: "Exact words they said or wrote, not paraphrased."

# A real person's name/credential for a byline — only if this is genuinely
# who stands behind the content.
author:
  name: ""
  credential: ""

# Real questions your customers actually ask, with real answers — these
# get published as a visible FAQ section AND matching schema together,
# so the two always match (a mismatch is what search engines penalize).
faq: []
#  - q: "Do you offer monthly SEO packages?"
#    a: "Yes — see appsage.in/services.php for current packages."
"""


def load_cfg() -> dict:
    if not BF_CFG.exists():
        BF_CFG.write_text(DEFAULT_CFG, encoding="utf-8")
    cfg = yaml.safe_load(BF_CFG.read_text(encoding="utf-8")) or {}
    cfg.setdefault("phone", "")
    cfg.setdefault("email", "")
    cfg.setdefault("stats_blurb", "")
    cfg.setdefault("testimonials", [])
    cfg.setdefault("author", {"name": "", "credential": ""})
    cfg.setdefault("faq", [])
    return cfg


def save_cfg(cfg: dict):
    BF_CFG.write_text(yaml.safe_dump(cfg, sort_keys=False, allow_unicode=True),
                      encoding="utf-8")
