ricecoder_generation/
models.rs

1//! Core data models for code generation
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use std::path::PathBuf;
6
7/// Represents a code template with placeholders
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Template {
10    /// Unique identifier for the template
11    pub id: String,
12    /// Human-readable name
13    pub name: String,
14    /// Programming language
15    pub language: String,
16    /// Template content with placeholders
17    pub content: String,
18    /// List of placeholders in the template
19    pub placeholders: Vec<Placeholder>,
20    /// Template metadata
21    pub metadata: TemplateMetadata,
22}
23
24/// Metadata about a template
25#[derive(Debug, Clone, Default, Serialize, Deserialize)]
26pub struct TemplateMetadata {
27    /// Template description
28    pub description: Option<String>,
29    /// Template version
30    pub version: Option<String>,
31    /// Template author
32    pub author: Option<String>,
33}
34
35/// Represents a placeholder in a template
36#[derive(Debug, Clone, Serialize, Deserialize)]
37pub struct Placeholder {
38    /// Placeholder name
39    pub name: String,
40    /// Human-readable description
41    pub description: String,
42    /// Default value if not provided
43    pub default: Option<String>,
44    /// Whether this placeholder is required
45    pub required: bool,
46}
47
48/// Case transformation options for placeholders
49#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
50pub enum CaseTransform {
51    /// PascalCase (e.g., MyProject)
52    PascalCase,
53    /// camelCase (e.g., myProject)
54    CamelCase,
55    /// snake_case (e.g., my_project)
56    SnakeCase,
57    /// kebab-case (e.g., my-project)
58    KebabCase,
59    /// UPPERCASE (e.g., MY_PROJECT)
60    UpperCase,
61    /// lowercase (e.g., myproject)
62    LowerCase,
63}
64
65/// Context for template rendering
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct TemplateContext {
68    /// Variable values for substitution
69    pub values: HashMap<String, String>,
70    /// Rendering options
71    pub options: RenderOptions,
72}
73
74/// Options for template rendering
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct RenderOptions {
77    /// Whether to format output
78    pub format_output: bool,
79    /// Whether to validate syntax
80    pub validate_syntax: bool,
81    /// Whether to preserve whitespace
82    pub preserve_whitespace: bool,
83}
84
85impl Default for RenderOptions {
86    fn default() -> Self {
87        Self {
88            format_output: true,
89            validate_syntax: true,
90            preserve_whitespace: false,
91        }
92    }
93}
94
95/// Result of template rendering
96#[derive(Debug, Clone, Serialize, Deserialize)]
97pub struct RenderResult {
98    /// Rendered content
99    pub content: String,
100    /// Warnings during rendering
101    pub warnings: Vec<String>,
102    /// Placeholders that were used
103    pub placeholders_used: Vec<String>,
104}
105
106/// Represents a boilerplate project scaffold
107#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct Boilerplate {
109    /// Unique identifier
110    pub id: String,
111    /// Human-readable name
112    pub name: String,
113    /// Description
114    pub description: String,
115    /// Programming language
116    pub language: String,
117    /// Files in the boilerplate
118    pub files: Vec<BoilerplateFile>,
119    /// Dependencies to install
120    pub dependencies: Vec<Dependency>,
121    /// Setup scripts to run
122    pub scripts: Vec<Script>,
123}
124
125/// A file in a boilerplate
126#[derive(Debug, Clone, Serialize, Deserialize)]
127pub struct BoilerplateFile {
128    /// File path relative to project root
129    pub path: String,
130    /// Template content or file reference
131    pub template: String,
132    /// Optional condition for including this file
133    pub condition: Option<String>,
134}
135
136/// A dependency for a boilerplate
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub struct Dependency {
139    /// Dependency name
140    pub name: String,
141    /// Dependency version
142    pub version: String,
143}
144
145/// A setup script for a boilerplate
146#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct Script {
148    /// Script name
149    pub name: String,
150    /// Script command
151    pub command: String,
152}
153
154/// Metadata about a boilerplate
155#[derive(Debug, Clone, Serialize, Deserialize)]
156pub struct BoilerplateMetadata {
157    /// Unique identifier
158    pub id: String,
159    /// Human-readable name
160    pub name: String,
161    /// Description
162    pub description: String,
163    /// Programming language
164    pub language: String,
165    /// Source location of the boilerplate
166    pub source: BoilerplateSource,
167}
168
169/// Source location of a boilerplate
170#[derive(Debug, Clone, Serialize, Deserialize)]
171pub enum BoilerplateSource {
172    /// Global boilerplate location
173    Global(PathBuf),
174    /// Project-specific boilerplate location
175    Project(PathBuf),
176}
177
178/// Conflict resolution strategy
179#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
180pub enum ConflictResolution {
181    /// Skip the conflicting file
182    Skip,
183    /// Overwrite the existing file
184    Overwrite,
185    /// Merge with existing file
186    Merge,
187}
188
189/// Result of boilerplate discovery
190#[derive(Debug, Clone, Serialize, Deserialize)]
191pub struct BoilerplateDiscoveryResult {
192    /// Found boilerplates
193    pub boilerplates: Vec<BoilerplateMetadata>,
194    /// Paths that were searched
195    pub search_paths: Vec<PathBuf>,
196}
197
198/// A generated code file
199#[derive(Debug, Clone, Serialize, Deserialize)]
200pub struct GeneratedFile {
201    /// File path relative to project root
202    pub path: String,
203    /// File content
204    pub content: String,
205    /// Programming language
206    pub language: String,
207}
208
209/// Result of code validation
210#[derive(Debug, Clone, Serialize, Deserialize)]
211pub struct ValidationResult {
212    /// Whether validation passed
213    pub valid: bool,
214    /// Validation errors found
215    pub errors: Vec<ValidationError>,
216    /// Validation warnings found
217    pub warnings: Vec<ValidationWarning>,
218}
219
220impl Default for ValidationResult {
221    fn default() -> Self {
222        Self {
223            valid: true,
224            errors: Vec::new(),
225            warnings: Vec::new(),
226        }
227    }
228}
229
230/// A validation error
231#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct ValidationError {
233    /// File path where error occurred
234    pub file: String,
235    /// Line number where error occurred
236    pub line: usize,
237    /// Column number where error occurred
238    pub column: usize,
239    /// Error message
240    pub message: String,
241    /// Error code (e.g., "E0001")
242    pub code: Option<String>,
243}
244
245/// A validation warning
246#[derive(Debug, Clone, Serialize, Deserialize)]
247pub struct ValidationWarning {
248    /// File path where warning occurred
249    pub file: String,
250    /// Line number where warning occurred
251    pub line: usize,
252    /// Column number where warning occurred
253    pub column: usize,
254    /// Warning message
255    pub message: String,
256    /// Warning code (e.g., "W0001")
257    pub code: Option<String>,
258}
259
260/// Configuration for code validation
261#[derive(Debug, Clone, Serialize, Deserialize)]
262pub struct ValidationConfig {
263    /// Whether to check syntax
264    pub check_syntax: bool,
265    /// Whether to run linters
266    pub run_linters: bool,
267    /// Whether to run type checking
268    pub run_type_checking: bool,
269    /// Whether to treat warnings as errors
270    pub warnings_as_errors: bool,
271}