"""Basic field encryption example."""

import asyncio

from pydynox import Model, ModelConfig
from pydynox.attributes import EncryptedAttribute, StringAttribute


class User(Model):
    model_config = ModelConfig(table="users")

    pk = StringAttribute(partition_key=True)
    sk = StringAttribute(sort_key=True)
    email = StringAttribute()
    ssn = EncryptedAttribute(key_id="alias/my-app-key")


async def main():
    # Create a user with sensitive data
    user = User(
        pk="USER#ENC",
        sk="PROFILE",
        email="john@example.com",
        ssn="123-45-6789",
    )
    await user.save()

    # The SSN is encrypted in DynamoDB as "ENC:base64data..."
    # When you read it back, it's decrypted automatically
    loaded = await User.get(pk="USER#ENC", sk="PROFILE")
    print(loaded.ssn)  # "123-45-6789"


asyncio.run(main())
