1use async_trait::async_trait;
2use facet::Facet;
3use facet_json::{DeserializeError, JsonError};
4
5#[derive(thiserror::Error, Debug)]
6pub enum ClientError {
7 #[error("Database error: {0}")]
8 MalformedIql(#[from] issuecraft_ql::ParseError),
9 #[error("Deserialization error: {0}")]
10 DeserializationError(#[from] DeserializeError<JsonError>),
11 #[error("Client specific: {0}")]
12 ClientSpecific(String),
13 #[error("Not implemented")]
14 NotImplemented,
15 #[error("This action is not supported by the chosen backend")]
16 NotSupported,
17}
18
19#[derive(Debug, Clone, Facet)]
20#[facet(transparent)]
21pub struct UserId(pub String);
22
23#[derive(Debug, Clone, Facet)]
24pub struct UserInfo {
25 pub display: Option<String>,
26 pub email: String,
27}
28
29#[derive(Debug, Clone, Facet)]
30#[facet(transparent)]
31pub struct ProjectId(pub String);
32
33#[derive(Debug, Clone, Facet)]
34pub struct ProjectInfo {
35 pub owner: UserId,
36 pub display: Option<String>,
37}
38
39#[derive(Debug, Clone, Facet)]
40#[repr(C)]
41pub enum CloseReason {
42 Duplicate,
43 WontFix,
44 Fixed,
45}
46
47#[derive(Debug, Clone, Facet)]
48#[repr(C)]
49pub enum IssueStatus {
50 Open,
51 Assigned,
52 Blocked,
53 Closed { reason: CloseReason },
54}
55
56#[derive(Debug, Clone, Facet)]
57#[facet(transparent)]
58pub struct IssueId(pub String);
59
60#[derive(Debug, Clone, Facet)]
61pub struct IssueInfo {
62 pub title: String,
63 pub description: String,
64 pub status: IssueStatus,
65 pub project: ProjectId,
66}
67
68#[derive(Debug, Clone, Facet)]
69#[facet(transparent)]
70pub struct CommentId(pub String);
71
72#[derive(Debug, Clone, Facet)]
73pub struct CommentInfo {
74 pub created_at: time::UtcDateTime,
75 pub content: String,
76 pub author: UserId,
77}
78
79#[derive(Debug, Clone)]
80pub enum AuthenticationInfo {
81 Password { password: String },
82 Token { token: String },
83 Certificate { path: Vec<u8> },
84}
85
86#[derive(Debug, Clone)]
87pub struct LoginInfo {
88 pub user: String,
89 pub auth: AuthenticationInfo,
90}
91
92#[async_trait]
93pub trait Client {
94 async fn login(&mut self, login: LoginInfo) -> Result<(), ClientError>;
95 async fn logout(&mut self) -> Result<(), ClientError>;
96 async fn execute(&mut self, query: &str) -> Result<String, ClientError>;
97}
98
99pub trait Backend {
100 fn init(&mut self) {}
101}