# Import our application factory and database tools
from app import create_app
from app.extensions import db
from app.models.role import Role

# 1. Start the engine (app) so we can connect to the database
app = create_app()

def seed_roles():
    # We need the app context to talk to the database
    with app.app_context():
        # The 4 main roles required for the NGO foundation
        ngo_roles = ['Admin', 'Verifier', 'Finance', 'Volunteer']
        for r_name in ngo_roles:
            # Check if the role already exists so we don't add duplicates
            existing_role = Role.query.filter_by(role_name=r_name).first()

            if not existing_role:
                # Create a new role and add it to our session (cart)
                new_role = Role(role_name=r_name)
                db.session.add(new_role)
                print(f"Added role: {r_name}")

        # Save (commit) all the changes to the actual database
        db.session.commit()
        print("Role seeding completed.")

# Run the function if this script is executed directly
if __name__ == "__main__":
    seed_roles()

