#!/usr/bin/env python3
"""
Simple script to set admin password for Sharey
"""
import hashlib
import json

def set_admin_password(password):
    """Set admin password in config.json"""
    try:
        # Load current config
        with open('config.json', 'r') as f:
            config = json.load(f)
        
        # Hash the password
        password_hash = hashlib.sha256(password.encode()).hexdigest()
        
        # Ensure admin section exists
        if 'admin' not in config:
            config['admin'] = {}
        
        config['admin']['password_hash'] = password_hash
        config['admin']['session_timeout_minutes'] = config['admin'].get('session_timeout_minutes', 30)
        
        # Save config
        with open('config.json', 'w') as f:
            json.dump(config, f, indent=2)
        
        print("✅ Admin password set successfully!")
        print("💡 You can now access the admin panel at /admin")
        return True
        
    except Exception as e:
        print(f"❌ Error setting admin password: {e}")
        return False

if __name__ == "__main__":
    import sys
    
    if len(sys.argv) != 2:
        print("Usage: python set_admin_password.py <password>")
        print("Example: python set_admin_password.py mySecurePassword123")
        sys.exit(1)
    
    password = sys.argv[1]
    
    if len(password) < 6:
        print("❌ Password must be at least 6 characters long")
        sys.exit(1)
    
    set_admin_password(password)
