# `PhoenixKit.Modules.CustomerService.TicketAttachment`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/modules/customer_service/ticket_attachment.ex#L1)

Junction schema for ticket and comment attachments.

Links tickets or comments to uploaded files (images, documents, etc.)
with ordering and optional captions. An attachment belongs to either
a ticket directly OR a comment, but not both.

## Fields

- `ticket_uuid` - Reference to ticket (if attached to ticket directly)
- `comment_uuid` - Reference to comment (if attached to comment)
- `file_uuid` - Reference to the uploaded file (PhoenixKit.Storage.File)
- `position` - Display order (1, 2, 3, etc.)
- `caption` - Optional caption/alt text

Note: Either `ticket_uuid` OR `comment_uuid` must be set, but not both.

## Examples

    # Attachment on ticket itself
    %TicketAttachment{
      ticket_uuid: "018e3c4a-9f6b-7890-abcd-ef1234567890",
      comment_uuid: nil,
      file_uuid: "018e3c4a-1234-5678-abcd-ef1234567890",
      position: 1,
      caption: "Screenshot of the error"
    }

    # Attachment on a comment
    %TicketAttachment{
      ticket_uuid: nil,
      comment_uuid: "018e3c4a-5678-1234-abcd-ef1234567890",
      file_uuid: "018e3c4a-abcd-efgh-ijkl-mnopqrstuvwx",
      position: 1,
      caption: nil
    }

# `t`

```elixir
@type t() :: %PhoenixKit.Modules.CustomerService.TicketAttachment{
  __meta__: term(),
  caption: String.t() | nil,
  comment:
    PhoenixKit.Modules.CustomerService.TicketComment.t()
    | Ecto.Association.NotLoaded.t()
    | nil,
  comment_uuid: UUIDv7.t() | nil,
  file: PhoenixKit.Modules.Storage.File.t() | Ecto.Association.NotLoaded.t(),
  file_uuid: UUIDv7.t(),
  inserted_at: DateTime.t() | nil,
  position: integer(),
  ticket:
    PhoenixKit.Modules.CustomerService.Ticket.t()
    | Ecto.Association.NotLoaded.t()
    | nil,
  ticket_uuid: UUIDv7.t() | nil,
  updated_at: DateTime.t() | nil,
  uuid: UUIDv7.t() | nil
}
```

# `changeset`

Changeset for creating or updating an attachment.

## Required Fields

- `file_uuid` - Reference to file
- `position` - Display order (must be positive)
- Either `ticket_uuid` OR `comment_uuid` (but not both)

## Validation Rules

- Position must be greater than 0
- Must have exactly one of ticket_uuid or comment_uuid

# `comment_attachment?`

Check if attachment is attached to a comment.

# `ticket_attachment?`

Check if attachment is attached to a ticket directly.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
