import os
from datetime import date


def generate_tos_txt(
    company_name: str = "Example Corp",
    service_name: str = "Example Service",
    contact_email: str = "support@example.com",
    effective_date: str | None = None,
):
    """
    Generate contents of a terms of service (tos.txt) file.

    :param company_name: Name of the company.
    :param service_name: Name of the service covered by the terms.
    :param contact_email: Email for contact.
    :param effective_date: Optional effective date (default is today).
    :return: String content of tos.txt.
    """
    if effective_date is None:
        effective_date = date.today().isoformat()

    content = f"""Terms of Service
Effective Date: {effective_date}

Welcome to {service_name}, operated by {company_name}.

By accessing or using our service, you agree to be bound by these terms.

1. Use of the Service
You agree to use {service_name} in compliance with all applicable laws and not for any unlawful purpose.

2. Account Responsibility
You are responsible for maintaining the confidentiality of your account credentials.

3. Intellectual Property
All content provided by {service_name} is the property of {company_name} and protected by intellectual property laws.

4. Termination
We reserve the right to suspend or terminate your access to the service at our discretion.

5. Changes to Terms
{company_name} may update these terms at any time. Continued use after changes means acceptance of those changes.

6. Contact Us
If you have any questions, please contact us at {contact_email}.
"""
    return content


def save_tos_txt(path: str = "tos.txt") -> None:
    """
    Save the generated TOS content to a file. If path is a directory,
    create a tos.txt file inside it.
    """
    if os.path.isdir(path):
        path = os.path.join(path, "tos.txt")
    content = generate_tos_txt()
    with open(path, "w") as f:
        f.write(content)
    print(f"'tos.txt' has been written to {path}")


if __name__ == "__main__":
    save_tos_txt()
