# API: Empresas

---

- [Index](#index)
- [Show](#show)
- [Store](#store)
- [Comodato Ativo](#comodato_ativo)
- [Comodatos](#comodatos)
- [Propriedades](#propriedades)
- [Produtos](#produtos)
- [Instalações](#instalacoes)
- [Ordens de Instalação](#ordens_instalacoes)
- [Silobags](#silobags)
- [Zonas](#zonas)

<a name="index"></a>
## Index

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "cnpj": <cnpj>,
        "razao_social": <razao_social>,
        "nome_fantasia": <nome_fantasia>,
        "email": <email>,
        "logo_file": <logo_file>,
        "is_active": <is_active>,
        "assinatura_contrato_at": <assinatura_contrato_at>,
        "logo_url": <logo_url>
    },
    //...
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="show"></a>
## Show

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
{
    "id": <id>,
    "cnpj": <cnpj>,
    "razao_social": <razao_social>,
    "nome_fantasia": <nome_fantasia>,
    "email": <email>,
    "logo_file": <logo_file>,
    "is_active": <is_active>,
    "assinatura_contrato_at": <assinatura_contrato_at>,
    "logo_url": <logo_url>
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="store"></a>
## Store

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|POST|`/empresas/{empresa}`|Default|

### Body
```json
{
    "razao_social": string,
    "nome_fantasia": string,
    "cnpj": string(cnpj),
    "email": string(email),
    "assinatura_contrato_at": string(Y-m-d H:i:s),
    "admin_user": {
        "name" : string,
        "email" : string(email),
        "cpf" : string(cpf)
    }
}
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
{
    "id": <id>,
    "cnpj": <cnpj>,
    "razao_social": <razao_social>,
    "nome_fantasia": <nome_fantasia>,
    "email": <email>,
    "logo_file": <logo_file>,
    "is_active": <is_active>,
    "assinatura_contrato_at": <assinatura_contrato_at>,
    "logo_url": <logo_url>
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="comodato_ativo"></a>
## Comodato Ativo

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/comodato-ativo`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
{
    "id": <id>,
    "empresa_id": <empresa_id>,
    "data_inicio": <data_inicio>,
    "data_fim": <data_fim>,
    "active": <active>,
    "equipamentos": [
        {
            "id": <id>,
            "code": <code>,
            "tipo": <tipo>,
            "modelo": <modelo>,
            "versao_hardware": <versao_hardware>,
            "versao_software": <versao_software>,
            "instalacao_id": <instalacao_id>,
            "pivot": {
                "comodato_id": <comodato_id>,
                "equipamento_id": <equipamento_id>
            }
        },
        //...
    ]
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="comodatos"></a>
## Comodatos

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/comodatos`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "data_inicio": <data_inicio>,
        "data_fim": <data_fim>,
        "active": <active>
    },
    //..
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="propriedades"></a>
## Propriedades

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/propriedades`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "nome": <nome>,
        "descricao": <descricao>,
        "center_lat": <center_lat>,
        "center_lng": <center_lng>,
        "area_polygon": [
            [
                <lat>,
                <lng>
            ],
            //...
        ],
        "profile_picture_file": <profile_picture_file>,
        "profile_picture_url": <profile_picture_url>
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```
---
### Endpoint
|Método|URI|Headers|
|:|:-|:|
|POST|`/empresas/{empresa}/propriedades`|Default|

### Body
```json
{
    "empresa_id": int,
    "nome": string,
    "descricao": string,
    "center_lat": float,
    "center_lng": float,
    "area_polygon": [
        [
            float, 
            float
        ],
        //... 
    ],
    "profile_picture_temp": string
}
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "nome": <nome>,
        "descricao": <descricao>,
        "center_lat": <center_lat>,
        "center_lng": <center_lng>,
        "area_polygon": [
            [
                <lat>,
                <lng>
            ],
            //...
        ],
        "profile_picture_file": <profile_picture_file>,
        "profile_picture_url": <profile_picture_url>
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="produtos"></a>
## Produtos

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/produtos`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "nome": <nome>,
        "descricao": <descricao>
    },
    //...
]
```
---
### Endpoint
|Método|URI|Headers|
|:|:-|:|
|POST|`/empresas/{empresa}/produtos`|Default|

### Body
```json
{
    "nome": string,
    "descricao": string,
    "default_ativos_referencias": [
        {
            "ativo_medicao_id": int,
            "min_val": float,
            "max_val": float
        },
        //...
    ]
}
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "nome": <nome>,
        "descricao": <descricao>
    },
    //...
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="instalacoes"></a>
## Instalações

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/instalacoes`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "equipamento_id": <id>,
        "ordem_instalacao_id": <id>,
        "secao_id": <id>,
        "latitude": <id>,
        "longitude": <id>,
        "installation_picture":<id>,
        "installation_observation": <id>,
        "installed_at": <id>,
        "installation_warning": <id>
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="ordens_instalacoes"></a>
## Ordens de Instalação

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/ordens-instalacao`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "empresa_id": <empresa_id>,
        "propriedade_id": <propriedade_id>,
        "zona_id": <zona_id>,
        "responsible_user_id": <iresponsible_user_idd>,
        "quantity": <quantity>,
        "installed_quantity": <installed_quantity>,
        "description": <description>,
        "target_date": <target_date>,
        "started_at": <started_at>,
        "finished_at": <finished_at>,
        "active": <active>
    },
    //...
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

---

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|POST|`/empresas/{empresa}/ordens-instalacao`|Default|

### Body
```json
{
    "zona_id": int,
    "quantity": int,
    "description": string,
    "target_date": string(Y-m-d)
}
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
{
    "zona_id": <zona_id>,
    "quantity": <quantity>,,
    "description": <description>,,
    "target_date": <target_date>,,
    "propriedade_id": <propriedade_id>,,
    "empresa_id": <empresa_id>,,
    "id": <id>,,
    "active": <active>,
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

---

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|PATCH|`/empresas/{empresa}/ordens-instalacao/{ordem-instalacao}/start`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
{
    "zona_id": <zona_id>,
    "quantity": <quantity>,,
    "description": <description>,,
    "target_date": <target_date>,,
    "propriedade_id": <propriedade_id>,,
    "empresa_id": <empresa_id>,,
    "id": <id>,,
    "active": <active>,
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-exclamation" style="margin-right:9px"></i>422 - Unprocessable Content</larecipe-badge>
```json
{
    "message": "A ordem de instalação já foi iniciada.",
    "errors": {
        "started_at": [
            "A ordem de instalação já foi iniciada."
        ]
    }
}
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

---

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|PATCH|`/empresas/{empresa}/ordens-instalacao/{ordem-instalacao}/finish`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
Empty
```

<larecipe-badge type="danger" rounded><i class="fa fa-exclamation" style="margin-right:9px"></i>422 - Unprocessable Content</larecipe-badge>
```json
{
    "message": "A ordem de instalação já foi finalizada.",
    "errors": {
        "started_at": [
            "A ordem de instalação já foi finalizada."
        ]
    }
}
```
```json
{
    "message": "Não foram instaladas todas sondas previstas. Instaladas 0 de 2.",
    "errors": {
        "installed_quantity": [
            "Não foram instaladas todas sondas previstas. Instaladas 0 de 2."
        ]
    }
}

```
<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="silobags"></a>
## Silobags

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/silobags`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "zona_id": <zona_id>,
        "propriedade_id": <propriedade_id>,
        "empresa_id": <empresa_id>,
        "produto_id": <produto_id>,
        "referencia_id": <referencia_id>,
        "identificacao": <identificacao>,
        "descricao": <descricao>,
        "center_lat": <center_lat>,
        "center_lng": <center_lng>,
        "length": <length>,
        "reta": [
            [
                <lat>,
                <lng>
            ],
            //..
        ],
        "has_alerta": <has_alerta>
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|POST|`/empresas/{empresa}/silobags`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "zona_id": <zona_id>,
        "propriedade_id": <propriedade_id>,
        "empresa_id": <empresa_id>,
        "produto_id": <produto_id>,
        "referencia_id": <referencia_id>,
        "identificacao": <identificacao>,
        "descricao": <descricao>,
        "center_lat": <center_lat>,
        "center_lng": <center_lng>,
        "length": <length>,
        "reta": [
            [
                <lat>,
                <lng>
            ],
            //..
        ],
        "has_alerta": <has_alerta>
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```

<a name="zonas"></a>
## Zonas

### Endpoint
|Método|URI|Headers|
|:|:-|:|
|GET|`/empresas/{empresa}/silobags`|Default|

### Body
```json
Empty
```

### Responses
<larecipe-badge type="success" rounded><i class="fa fa-check" style="margin-right:9px"></i>200 - OK</larecipe-badge>
```json
[
    {
        "id": <id>,
        "propriedade_id": <propriedade_id>,
        "empresa_id": <empresa_id>,
        "identificacao": <identificacao>,
        "descricao": <descricao>,
        "center_lat": <center_lat>,
        "center_lng": <center_lng>,
        "area_polygon": [
            [
                <lat>,
                <lng>
            ],
            //...
        ],
        "profile_picture_file": <profile_picture_file>,
        "profile_picture_url": <profile_picture_url>,
        "propriedade": {
            "id": <id>,
            "empresa_id": <empresa_id>,
            "nome": <nome,
            "descricao": <descricao>,
            "center_lat": <center_lat>,
            "center_lng": <center_lng>,
            "area_polygon": [
                [
                    <lat>,
                    <lng>
                ],
                //...
            ],
            "profile_picture_file": <profile_picture_file>,
            "profile_picture_url": <profile_picture_url>
        }
    }
]
```

<larecipe-badge type="danger" rounded><i class="fa fa-lock" style="margin-right:9px"></i>401 - Unauthorized</larecipe-badge>
```json
{
    "message": "Unauthenticated."
}
```