# Data Model: Event Management App

## Entities

### AdminUser (Stored in PocketBase)
- **id**: UUID
- **email**: String
- **password_hash**: String
- **role**: Enum (`superadmin`, `financeiro`, `administrador`, `recepcao`)

### Event
- **id**: Integer (Primary Key)
- **title**: String
- **description**: Text
- **cover_image_url**: String (Stored in PocketBase, referenced by URL)
- **event_date**: DateTime
- **location**: String
- **status**: String (Enum: DRAFT, ACTIVE, FINISHED)
- **badge_width_cm**: Decimal (default 8.0)
- **badge_height_cm**: Decimal (default 4.0)
- **created_at**: DateTime
- **updated_at**: DateTime

### TicketCategory
- **id**: Integer (Primary Key)
- **event_id**: Integer (Foreign Key -> Event)
- **name**: String (e.g., Student, Corporate)
- **description**: Text (optional)

### TicketBatch
- **id**: Integer (Primary Key)
- **ticket_category_id**: Integer (Foreign Key -> TicketCategory)
- **name**: String (e.g., Early Bird)
- **price**: Decimal
- **start_date**: DateTime
- **end_date**: DateTime
- **capacity**: Integer (optional, if we want to limit tickets)

### Order
- **id**: Integer (Primary Key)
- **batch_id**: Integer (Foreign Key -> TicketBatch)
- **attendee_name**: String
- **attendee_email**: String
- **attendee_document**: String (required for ASAAS, e.g., CPF or CNPJ)
- **asaas_customer_id**: String (optional, ASAAS customer reference)
- **asaas_payment_id**: String (optional, ASAAS payment reference)
- **payment_method**: String (Enum: PIX, CREDIT_CARD, MANUAL)
- **invoice_url**: String (optional, URL for ASAAS hosted checkout for Credit Card)
- **pix_qr_code**: Text (optional, payload for Pix copy-paste)
- **pix_qr_code_url**: String (optional, image URL for Pix QR code)
- **attendee_nationality**: String (optional)
- **attendee_phone**: String (optional)
- **attendee_country**: String (optional)
- **attendee_state**: String (optional)
- **attendee_city**: String (optional)
- **attendee_oab**: String (optional)
- **status**: String (Enum: PENDING, APPROVED, CANCELLED, FAILED)
- **created_at**: DateTime
- **updated_at**: DateTime

### Ticket
- **id**: Integer (Primary Key)
- **order_id**: Integer (Foreign Key -> Order)
- **ticket_code**: String (Unique identifier/QR code string)
- **issued_at**: DateTime
- **checked_in_at**: DateTime (optional, timestamp when check-in was confirmed)

## Validation Rules
- `Order` must have a valid `batch_id` that is currently active (`start_date` <= now <= `end_date`).
- `TicketBatch` dates within the same category should generally not overlap.
- `Event` cover images must be valid image formats.

## State Transitions
**Order Status**:
- `PENDING` -> `APPROVED` (When ASAAS webhook confirms payment OR admin manually approves)
- `PENDING` -> `FAILED` (If payment is rejected by ASAAS)
- `PENDING` -> `CANCELLED` (If admin rejects, attendee cancels, or ASAAS billing expires)