#!/usr/bin/env python
import argparse

from cover_letter_autofill_shared import export_cover_letter_to_text_file, export_cover_letter_to_pdf

def main():
    parser = argparse.ArgumentParser(description='Cover letter autofill')
    parser.add_argument('--job_title', '-jt', required=True, help='Job title')
    parser.add_argument('--company_name', '-cn', required=True, help='Company name')
    parser.add_argument('--hiring_manager_name', '-hmn', required=False, help='Hiring manager name', default='Hiring Manager')
    parser.add_argument('--job_reference', '-jr', required=False, help='Job reference', default='')
    parser.add_argument('--requirement', '-r', required=True, help='Job requirement')
    parser.add_argument('--tech_stack', '-jts', required=True, help='Job tech stack')
    
    args = parser.parse_args()

    job_title = args.job_title
    company_name = args.company_name
    hiring_manager_name = args.hiring_manager_name
    job_reference = args.job_reference
    requirement = args.requirement
    tech_stack = args.tech_stack
    
    print('\n')
    print('Arguments:')
    print(f'Job title: {job_title}')
    print(f'Company name: {company_name}')
    print(f'Hiring manager name: {hiring_manager_name}')
    print(f'Job reference: {job_reference}')
    print(f'Requirement: {requirement}')
    print(f'Tech stack: {tech_stack}')
    
    subject, cover_letter = make_cover_letter_for_job(
        job_title = job_title, 
        company_name = company_name, 
        hiring_manager_name = hiring_manager_name, 
        job_reference = job_reference,
        requirement = requirement,
        tech_stack = tech_stack
    )

    print('\n')
    print(f'Subject: {subject}')
    print(f'Cover letter: {cover_letter}')

    export_cover_letter_to_text_file(cover_letter)
    export_cover_letter_to_pdf(cover_letter)

def make_cover_letter_for_job(job_title, company_name, hiring_manager_name, job_reference, requirement, tech_stack):
    hiring_manager_name = "Hiring Manager" if hiring_manager_name == "" else hiring_manager_name
    return f"Application for {job_title} Position {'' if job_reference == '' else f' - {job_reference}'}", f"""
Dear {hiring_manager_name},

I'm writing to apply for the {job_title} position at {company_name}. Your need for {requirement} caught my attention, as I've tackled similar challenges in my work developing integrated e-commerce platforms and automated business systems.

I'm a pragmatic full-stack developer who focuses on delivering measurable business impact through technical solutions. I'm particularly strong in data-driven automation and system optimisation with {tech_stack}, having implemented solutions that significantly improved performance and ROI across multiple business contexts.

I'd welcome the opportunity to discuss how my technical expertise could help drive {company_name}'s success. My CV is attached for you review.

Best regards,
Edward Middleton-Smith
edward.middletonsmith@gmail.com
07375571430
https://teddy.org.uk/
https://www.linkedin.com/in/teddyms/
https://github.com/Teddy-1024/
    """

if __name__ == '__main__':
    main()