import yaml
from django.core.management.base import BaseCommand
from django.template import Template, Context
from backend.core.models import DocumentTemplate

class Command(BaseCommand):
    help = "Import document template from a YAML file"

    def add_arguments(self, parser):
        parser.add_argument('yaml_file', type=str, help="YAML file to import template from")

    def handle(self, *args, **options):
        yaml_file_path = options['yaml_file']

        with open(yaml_file_path, 'r') as file:
            content = file.read()

        DocumentTemplate.objects.update_or_create(
            name="Default Template",
            defaults={"content": content}
        )

        self.stdout.write(self.style.SUCCESS("Template imported successfully."))
