# `Fivetrex.Models.Connector`
[🔗](https://github.com/lostbean/fivetrex/blob/v0.2.3/lib/fivetrex/models/connector.ex#L1)

Represents a Fivetran Connector.

A Connector is the core operational entity in Fivetran, representing the
pipeline between a data source (e.g., Salesforce, PostgreSQL, Google Ads)
and a destination warehouse. Connectors handle the actual data extraction,
transformation, and loading (ELT).

## Fields

  * `:id` - The unique identifier for the connector
  * `:group_id` - The ID of the parent group
  * `:service` - The connector type (e.g., `"postgres"`, `"salesforce"`, `"google_ads"`)
  * `:service_version` - The version number of the connector service
  * `:schema` - The destination schema/dataset name
  * `:paused` - Whether the connector is paused
  * `:pause_after_trial` - Whether to pause after free trial ends
  * `:sync_frequency` - Sync interval in minutes
  * `:status` - A map containing sync state and timing information
  * `:setup_state` - Setup status (e.g., `"connected"`, `"incomplete"`)
  * `:created_at` - ISO 8601 timestamp of creation
  * `:succeeded_at` - ISO 8601 timestamp of last successful sync
  * `:failed_at` - ISO 8601 timestamp of last failed sync
  * `:config` - Service-specific configuration (connection details, etc.)
* `:connect_card` - OAuth redirect information (only present when created with `connect_card_config`)

## Status Map

The `:status` field contains detailed sync information:

```elixir
%{
  "sync_state" => "scheduled",     # Current state
  "update_state" => "on_schedule", # Update status
  "is_historical_sync" => false,   # Historical sync in progress?
  "tasks" => [...],                # Active tasks
  "warnings" => [...]              # Any warnings
}
```

## Sync States

The `sync_state` within the status map can be:

  * `"scheduled"` - Waiting for next scheduled sync
  * `"syncing"` - Currently syncing data
  * `"paused"` - Manually paused
  * `"rescheduled"` - Sync was rescheduled

## Helper Functions

This module provides helper functions to check connector state:

    if Connector.syncing?(connector) do
      IO.puts("Sync in progress...")
    end

    if Connector.paused?(connector) do
      IO.puts("Connector is paused")
    end

## Examples

Working with a connector:

    {:ok, connector} = Fivetrex.Connectors.get(client, "connector_id")
    IO.puts("Service: #{connector.service}")
    IO.puts("Schema: #{connector.schema}")
    IO.puts("Sync state: #{Connector.sync_state(connector)}")

Filtering connectors by state:

    {:ok, %{items: connectors}} = Fivetrex.Connectors.list(client, group_id)

    syncing = Enum.filter(connectors, &Connector.syncing?/1)
    paused = Enum.filter(connectors, &Connector.paused?/1)

## See Also

  * `Fivetrex.Connectors` - API functions for managing connectors
  * `Fivetrex.Models.Group` - Parent group for connectors

# `status`

```elixir
@type status() :: String.t()
```

The sync state string from the connector's status.

Common values: `"scheduled"`, `"syncing"`, `"paused"`, `"rescheduled"`

# `t`

```elixir
@type t() :: %Fivetrex.Models.Connector{
  config: map() | nil,
  connect_card: map() | nil,
  created_at: String.t() | nil,
  failed_at: String.t() | nil,
  group_id: String.t() | nil,
  id: String.t() | nil,
  pause_after_trial: boolean() | nil,
  paused: boolean() | nil,
  schema: String.t() | nil,
  service: String.t() | nil,
  service_version: integer() | nil,
  setup_state: String.t() | nil,
  status: map() | nil,
  succeeded_at: String.t() | nil,
  sync_frequency: integer() | nil
}
```

A Fivetran Connector struct.

All fields may be `nil` if not provided in the API response.

# `from_map`

```elixir
@spec from_map(map()) :: t()
```

Converts a map (from JSON response) to a Connector struct.

This function is used internally by `Fivetrex.Connectors` functions to parse
API responses into typed structs.

## Parameters

  * `map` - A map with string keys from a decoded JSON response

## Returns

A `%Fivetrex.Models.Connector{}` struct with fields populated from the map.

## Examples

    iex> map = %{"id" => "conn_123", "service" => "postgres", "paused" => false}
    iex> connector = Fivetrex.Models.Connector.from_map(map)
    iex> connector.service
    "postgres"

# `paused?`

```elixir
@spec paused?(t()) :: boolean()
```

Returns true if the connector is paused.

A paused connector will not sync until resumed via `Fivetrex.Connectors.resume/2`.

## Parameters

  * `connector` - A `%Fivetrex.Models.Connector{}` struct

## Returns

  * `true` - If the connector is paused
  * `false` - If the connector is active (not paused)

## Examples

    if Connector.paused?(connector) do
      IO.puts("Connector is paused, resuming...")
      Fivetrex.Connectors.resume(client, connector.id)
    end

    # Find all paused connectors
    paused_connectors = Enum.filter(connectors, &Connector.paused?/1)

# `sync_state`

```elixir
@spec sync_state(t()) :: String.t() | nil
```

Returns the sync state from the connector's status map.

The sync state indicates what the connector is currently doing.

## Parameters

  * `connector` - A `%Fivetrex.Models.Connector{}` struct

## Returns

  * `String.t()` - The sync state (e.g., `"scheduled"`, `"syncing"`, `"paused"`)
  * `nil` - If the status map is missing or doesn't contain sync_state

## Possible Values

  * `"scheduled"` - Waiting for next scheduled sync
  * `"syncing"` - Currently syncing data
  * `"paused"` - Connector is paused
  * `"rescheduled"` - Sync was rescheduled

## Examples

    iex> connector = %Fivetrex.Models.Connector{status: %{"sync_state" => "syncing"}}
    iex> Fivetrex.Models.Connector.sync_state(connector)
    "syncing"

    iex> connector = %Fivetrex.Models.Connector{status: nil}
    iex> Fivetrex.Models.Connector.sync_state(connector)
    nil

# `syncing?`

```elixir
@spec syncing?(t()) :: boolean()
```

Returns true if the connector is currently syncing.

This is a convenience function that checks if the sync_state is `"syncing"`.

## Parameters

  * `connector` - A `%Fivetrex.Models.Connector{}` struct

## Returns

  * `true` - If the connector is actively syncing data
  * `false` - If the connector is not syncing (scheduled, paused, etc.)

## Examples

    if Connector.syncing?(connector) do
      IO.puts("Sync in progress, please wait...")
    end

    # Find all syncing connectors
    syncing_connectors = Enum.filter(connectors, &Connector.syncing?/1)

---

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