"""
Sample tasks for the bugfix harness
"""


def get_sample_tasks():
    """Return a list of sample tasks for the bugfix harness"""
    return [
        {
            "id": "task_001",
            "description": "Fix failing test in auth.py",
            "files": {"auth.py": "", "test_auth.py": ""},
        }
    ]


def create_sample_repo():
    """Create a sample repository with failing tests for demonstration"""
    import os

    # Create a simple Python project with failing tests
    base_dir = "sample_project"
    os.makedirs(base_dir, exist_ok=True)

    # Get the tasks to know what to create
    tasks = get_sample_tasks()
    # We only have one task for the MVP
    task = tasks[0]

    # Create auth.py with intentional bug
    auth_content = '''def validate_password(password):
    """Validate a password"""
    # Bug: should require at least 8 characters
    if len(password) >= 10:  # Wrong: should be 8
        return True
    return False

def hash_password(password):
    """Hash a password (simplified)"""
    return hash(password)
'''

    with open(os.path.join(base_dir, "auth.py"), "w") as f:
        f.write(auth_content)

    # Create test_auth.py with failing tests
    test_auth_content = '''import unittest
from auth import validate_password, hash_password

class TestAuth(unittest.TestCase):
    
    def test_validate_password_short(self):
        """Test that short passwords are rejected"""
        self.assertFalse(validate_password("abc"))  # Too short
        self.assertFalse(validate_password("12345"))  # Too short
    
    def test_validate_password_long(self):
        """Test that long enough passwords are accepted"""
        self.assertTrue(validate_password("abcdefgh"))  # 8 chars
        self.assertTrue(validate_password("12345678"))  # 8 chars
    
    def test_validate_password_exact_length(self):
        """Test password at exact length threshold"""
        # This will fail with current implementation
        self.assertTrue(validate_password("12345678"))  # Should pass but fails
    
    def test_hash_password(self):
        """Test that hashing works"""
        hashed = hash_password("test")
        self.assertIsInstance(hashed, int)

if __name__ == '__main__':
    unittest.main()
'''
    with open(os.path.join(base_dir, "test_auth.py"), "w") as f:
        f.write(test_auth_content)

    print("Created sample project with failing tests in ./" + base_dir)
    print("Run: openharness play bugfix --workspace ./" + base_dir)


if __name__ == "__main__":
    create_sample_repo()
