1use async_graphql::{SimpleObject, InputObject, Enum};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq, Serialize, Deserialize)]
8pub enum TipoDocumento {
9 #[graphql(name = "NFE")]
10 Nfe,
11 #[graphql(name = "NFCE")]
12 Nfce,
13 #[graphql(name = "NFSE")]
14 Nfse,
15 #[graphql(name = "CTE")]
16 Cte,
17 #[graphql(name = "MDFE")]
18 Mdfe,
19}
20
21#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq, Serialize, Deserialize)]
23pub enum Ambiente {
24 #[graphql(name = "PRODUCAO")]
25 Producao,
26 #[graphql(name = "HOMOLOGACAO")]
27 Homologacao,
28}
29
30#[derive(Debug, Clone, Copy, Enum, Eq, PartialEq, Serialize, Deserialize)]
32pub enum StatusNfe {
33 #[graphql(name = "PENDENTE")]
34 Pendente,
35 #[graphql(name = "AUTORIZADA")]
36 Autorizada,
37 #[graphql(name = "CANCELADA")]
38 Cancelada,
39 #[graphql(name = "DENEGADA")]
40 Denegada,
41 #[graphql(name = "REJEITADA")]
42 Rejeitada,
43}
44
45#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
47pub struct NfeType {
48 pub id: String,
49 pub chave_acesso: String,
50 pub numero: i32,
51 pub serie: i32,
52 pub tipo: TipoDocumento,
53 pub ambiente: Ambiente,
54 pub status: StatusNfe,
55 pub data_emissao: String,
56 pub data_autorizacao: Option<String>,
57 pub protocolo: Option<String>,
58 pub emitente: EmitenteType,
59 pub destinatario: Option<DestinatarioType>,
60 pub itens: Vec<ItemType>,
61 pub totais: TotaisType,
62 pub xml: Option<String>,
63}
64
65#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
67pub struct EmitenteType {
68 pub cnpj: String,
69 pub razao_social: String,
70 pub nome_fantasia: Option<String>,
71 pub inscricao_estadual: Option<String>,
72 pub endereco: EnderecoType,
73}
74
75#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
77pub struct DestinatarioType {
78 pub cnpj: Option<String>,
79 pub cpf: Option<String>,
80 pub razao_social: String,
81 pub inscricao_estadual: Option<String>,
82 pub endereco: Option<EnderecoType>,
83}
84
85#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
87pub struct EnderecoType {
88 pub logradouro: String,
89 pub numero: String,
90 pub complemento: Option<String>,
91 pub bairro: String,
92 pub municipio: String,
93 pub uf: String,
94 pub cep: String,
95 pub pais: Option<String>,
96}
97
98#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
100pub struct ItemType {
101 pub numero: i32,
102 pub codigo: String,
103 pub descricao: String,
104 pub ncm: String,
105 pub cfop: String,
106 pub unidade: String,
107 pub quantidade: f64,
108 pub valor_unitario: f64,
109 pub valor_total: f64,
110}
111
112#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
114pub struct TotaisType {
115 pub base_calculo_icms: f64,
116 pub valor_icms: f64,
117 pub valor_produtos: f64,
118 pub valor_frete: f64,
119 pub valor_desconto: f64,
120 pub valor_total: f64,
121}
122
123#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
125pub struct ConsultaSefazResult {
126 pub sucesso: bool,
127 pub codigo_status: String,
128 pub motivo: String,
129 pub chave_acesso: Option<String>,
130 pub protocolo: Option<String>,
131 pub data_recebimento: Option<String>,
132 pub situacao: Option<String>,
133}
134
135#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
137pub struct EmissaoResult {
138 pub sucesso: bool,
139 pub codigo_status: String,
140 pub motivo: String,
141 pub chave_acesso: Option<String>,
142 pub protocolo: Option<String>,
143 pub xml_autorizado: Option<String>,
144}
145
146#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
148pub struct CancelamentoResult {
149 pub sucesso: bool,
150 pub codigo_status: String,
151 pub motivo: String,
152 pub protocolo: Option<String>,
153 pub data_cancelamento: Option<String>,
154}
155
156#[derive(Debug, Clone, SimpleObject, Serialize, Deserialize)]
158pub struct CertificadoInfoType {
159 pub cnpj: Option<String>,
160 pub razao_social: Option<String>,
161 pub valido: bool,
162 pub data_validade: String,
163 pub dias_para_expirar: i32,
164}
165
166#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
172pub struct NfeInput {
173 pub numero: i32,
174 pub serie: i32,
175 pub natureza_operacao: String,
176 pub ambiente: Ambiente,
177 pub emitente: EmitenteInput,
178 pub destinatario: Option<DestinatarioInput>,
179 pub itens: Vec<ItemInput>,
180}
181
182#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
184pub struct EmitenteInput {
185 pub cnpj: String,
186 pub razao_social: String,
187 pub nome_fantasia: Option<String>,
188 pub inscricao_estadual: Option<String>,
189 pub endereco: EnderecoInput,
190}
191
192#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
194pub struct DestinatarioInput {
195 pub cnpj: Option<String>,
196 pub cpf: Option<String>,
197 pub razao_social: String,
198 pub inscricao_estadual: Option<String>,
199 pub endereco: Option<EnderecoInput>,
200}
201
202#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
204pub struct EnderecoInput {
205 pub logradouro: String,
206 pub numero: String,
207 pub complemento: Option<String>,
208 pub bairro: String,
209 pub municipio: String,
210 pub codigo_municipio: String,
211 pub uf: String,
212 pub cep: String,
213}
214
215#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
217pub struct ItemInput {
218 pub codigo: String,
219 pub descricao: String,
220 pub ncm: String,
221 pub cfop: String,
222 pub unidade: String,
223 pub quantidade: f64,
224 pub valor_unitario: f64,
225}
226
227#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
229pub struct CancelamentoInput {
230 pub chave_acesso: String,
231 pub protocolo_autorizacao: String,
232 pub justificativa: String,
233}
234
235#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
237pub struct CartaCorrecaoInput {
238 pub chave_acesso: String,
239 pub sequencia: i32,
240 pub correcao: String,
241}
242
243#[derive(Debug, Clone, InputObject, Default, Serialize, Deserialize)]
245pub struct NfeFilter {
246 pub cnpj_emitente: Option<String>,
247 pub data_inicio: Option<String>,
248 pub data_fim: Option<String>,
249 pub status: Option<StatusNfe>,
250 pub numero: Option<i32>,
251}
252
253#[derive(Debug, Clone, InputObject, Serialize, Deserialize)]
255pub struct Pagination {
256 #[graphql(default = 0)]
257 pub offset: i32,
258 #[graphql(default = 20)]
259 pub limit: i32,
260}
261
262impl Default for Pagination {
263 fn default() -> Self {
264 Self { offset: 0, limit: 20 }
265 }
266}