@polymorphism-tech/morph-spec 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +279 -0
- package/bin/morph-spec.js +53 -0
- package/content/.claude/commands/morph-apply.md +66 -0
- package/content/.claude/commands/morph-archive.md +79 -0
- package/content/.claude/commands/morph-costs.md +206 -0
- package/content/.claude/commands/morph-infra.md +209 -0
- package/content/.claude/commands/morph-proposal.md +60 -0
- package/content/.claude/commands/morph-status.md +71 -0
- package/content/.claude/settings.local.json +15 -0
- package/content/.claude/skills/infra/bicep-architect.md +419 -0
- package/content/.claude/skills/infra/container-specialist.md +437 -0
- package/content/.claude/skills/infra/devops-engineer.md +405 -0
- package/content/.claude/skills/integrations/asaas-financial.md +333 -0
- package/content/.claude/skills/integrations/azure-identity.md +309 -0
- package/content/.claude/skills/integrations/clerk-auth.md +290 -0
- package/content/.claude/skills/specialists/azure-architect.md +142 -0
- package/content/.claude/skills/specialists/cost-guardian.md +110 -0
- package/content/.claude/skills/specialists/ef-modeler.md +200 -0
- package/content/.claude/skills/specialists/hangfire-orchestrator.md +245 -0
- package/content/.claude/skills/specialists/ms-agent-expert.md +209 -0
- package/content/.claude/skills/specialists/po-pm-advisor.md +197 -0
- package/content/.claude/skills/specialists/standards-architect.md +78 -0
- package/content/.claude/skills/specialists/ui-ux-designer.md +325 -0
- package/content/.claude/skills/stacks/dotnet-blazor.md +352 -0
- package/content/.claude/skills/stacks/dotnet-nextjs.md +402 -0
- package/content/.claude/skills/stacks/shopify.md +445 -0
- package/content/.morph/archive/.gitkeep +25 -0
- package/content/.morph/config/agents.json +149 -0
- package/content/.morph/config/config.template.json +96 -0
- package/content/.morph/examples/api-nextjs/README.md +241 -0
- package/content/.morph/examples/api-nextjs/contracts.ts +307 -0
- package/content/.morph/examples/api-nextjs/spec.md +399 -0
- package/content/.morph/examples/api-nextjs/tasks.md +168 -0
- package/content/.morph/examples/micro-saas/README.md +125 -0
- package/content/.morph/examples/micro-saas/contracts.cs +358 -0
- package/content/.morph/examples/micro-saas/decisions.md +246 -0
- package/content/.morph/examples/micro-saas/spec.md +236 -0
- package/content/.morph/examples/micro-saas/tasks.md +150 -0
- package/content/.morph/examples/multi-agent/README.md +309 -0
- package/content/.morph/examples/multi-agent/contracts.cs +433 -0
- package/content/.morph/examples/multi-agent/spec.md +479 -0
- package/content/.morph/examples/multi-agent/tasks.md +185 -0
- package/content/.morph/features/.gitkeep +25 -0
- package/content/.morph/project.md +159 -0
- package/content/.morph/specs/.gitkeep +20 -0
- package/content/.morph/standards/architecture.md +190 -0
- package/content/.morph/standards/azure.md +184 -0
- package/content/.morph/standards/coding.md +342 -0
- package/content/.morph/templates/agent.cs +172 -0
- package/content/.morph/templates/component.razor +239 -0
- package/content/.morph/templates/contracts.cs +217 -0
- package/content/.morph/templates/decisions.md +106 -0
- package/content/.morph/templates/infra/app-insights.bicep +63 -0
- package/content/.morph/templates/infra/container-app-env.bicep +49 -0
- package/content/.morph/templates/infra/container-app.bicep +156 -0
- package/content/.morph/templates/infra/key-vault.bicep +91 -0
- package/content/.morph/templates/infra/main.bicep +155 -0
- package/content/.morph/templates/infra/parameters.dev.json +23 -0
- package/content/.morph/templates/infra/parameters.prod.json +23 -0
- package/content/.morph/templates/infra/sql-database.bicep +103 -0
- package/content/.morph/templates/infra/storage.bicep +106 -0
- package/content/.morph/templates/integrations/asaas-client.cs +387 -0
- package/content/.morph/templates/integrations/asaas-webhook.cs +351 -0
- package/content/.morph/templates/integrations/azure-identity-config.cs +288 -0
- package/content/.morph/templates/integrations/clerk-config.cs +258 -0
- package/content/.morph/templates/job.cs +171 -0
- package/content/.morph/templates/migration.cs +83 -0
- package/content/.morph/templates/proposal.md +155 -0
- package/content/.morph/templates/recap.md +105 -0
- package/content/.morph/templates/repository.cs +141 -0
- package/content/.morph/templates/saas/subscription.cs +347 -0
- package/content/.morph/templates/saas/tenant.cs +338 -0
- package/content/.morph/templates/service.cs +139 -0
- package/content/.morph/templates/spec.md +147 -0
- package/content/.morph/templates/tasks.md +235 -0
- package/content/.morph/templates/test.cs +239 -0
- package/content/CLAUDE.md +318 -0
- package/package.json +50 -0
- package/src/commands/doctor.js +132 -0
- package/src/commands/init.js +121 -0
- package/src/commands/update.js +84 -0
- package/src/utils/file-copier.js +50 -0
- package/src/utils/logger.js +32 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Feature Recap: {Feature Name}
|
|
2
|
+
|
|
3
|
+
## 📋 Summary
|
|
4
|
+
|
|
5
|
+
| Field | Value |
|
|
6
|
+
|-------|-------|
|
|
7
|
+
| **Feature ID** | {feature-id} |
|
|
8
|
+
| **Completed** | {date} |
|
|
9
|
+
| **Total Tasks** | {X} |
|
|
10
|
+
| **Time Spent** | {X}h |
|
|
11
|
+
| **Agents Used** | {list} |
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ✅ What Was Delivered
|
|
16
|
+
|
|
17
|
+
### Functionality
|
|
18
|
+
- {Funcionalidade 1 entregue}
|
|
19
|
+
- {Funcionalidade 2 entregue}
|
|
20
|
+
- {Funcionalidade 3 entregue}
|
|
21
|
+
|
|
22
|
+
### Files Created
|
|
23
|
+
```
|
|
24
|
+
{lista de arquivos criados}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Files Modified
|
|
28
|
+
```
|
|
29
|
+
{lista de arquivos modificados}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 🏗️ Architecture Decisions
|
|
35
|
+
|
|
36
|
+
| Decision | Rationale |
|
|
37
|
+
|----------|-----------|
|
|
38
|
+
| {Decisão 1} | {Motivo} |
|
|
39
|
+
| {Decisão 2} | {Motivo} |
|
|
40
|
+
|
|
41
|
+
See full ADRs in `decisions.md`
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 🧪 Test Coverage
|
|
46
|
+
|
|
47
|
+
| Type | Files | Coverage |
|
|
48
|
+
|------|-------|----------|
|
|
49
|
+
| Unit Tests | {X} | {X}% |
|
|
50
|
+
| Integration Tests | {X} | {X}% |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 💰 Cost Impact
|
|
55
|
+
|
|
56
|
+
| Resource | Before | After | Delta |
|
|
57
|
+
|----------|--------|-------|-------|
|
|
58
|
+
| Azure SQL | $0 | $0 | $0 |
|
|
59
|
+
| Container Apps | $X | $X | +$X |
|
|
60
|
+
| Azure OpenAI | $X | $X | +$X |
|
|
61
|
+
| **Total** | | | **+$X/month** |
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 📝 Lessons Learned
|
|
66
|
+
|
|
67
|
+
### What Went Well
|
|
68
|
+
- {Ponto positivo 1}
|
|
69
|
+
- {Ponto positivo 2}
|
|
70
|
+
|
|
71
|
+
### What Could Be Improved
|
|
72
|
+
- {Ponto de melhoria 1}
|
|
73
|
+
- {Ponto de melhoria 2}
|
|
74
|
+
|
|
75
|
+
### Recommendations for Future
|
|
76
|
+
- {Recomendação 1}
|
|
77
|
+
- {Recomendação 2}
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## 🔗 Related Resources
|
|
82
|
+
|
|
83
|
+
- **Proposal:** `proposal.md`
|
|
84
|
+
- **Spec:** `spec.md`
|
|
85
|
+
- **Contracts:** `contracts.cs`
|
|
86
|
+
- **Tasks:** `tasks.md`
|
|
87
|
+
- **Decisions:** `decisions.md`
|
|
88
|
+
- **Azure DevOps Epic:** {link}
|
|
89
|
+
- **PR:** {link}
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 📊 Metrics
|
|
94
|
+
|
|
95
|
+
| Metric | Value |
|
|
96
|
+
|--------|-------|
|
|
97
|
+
| Tasks Completed | {X}/{X} |
|
|
98
|
+
| Checkpoints Passed | {X} |
|
|
99
|
+
| Code Reviews | {X} |
|
|
100
|
+
| Bugs Found | {X} |
|
|
101
|
+
| Bugs Fixed | {X} |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
*Generated by MORPH Framework on {date}*
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// REPOSITORY TEMPLATE
|
|
3
|
+
// Generated by MORPH Framework
|
|
4
|
+
// ============================================================
|
|
5
|
+
|
|
6
|
+
using Microsoft.EntityFrameworkCore;
|
|
7
|
+
using MyProject.Domain.Entities;
|
|
8
|
+
|
|
9
|
+
namespace MyProject.Infrastructure.Data.Repositories;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Repository for {Feature} data access.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public class {Feature}Repository(AppDbContext context) : I{Feature}Repository
|
|
15
|
+
{
|
|
16
|
+
private readonly DbSet<{Feature}> _dbSet = context.Set<{Feature}>();
|
|
17
|
+
|
|
18
|
+
/// <inheritdoc />
|
|
19
|
+
public async Task<{Feature}?> GetByIdAsync(int id, CancellationToken cancellationToken = default)
|
|
20
|
+
{
|
|
21
|
+
return await _dbSet
|
|
22
|
+
.AsNoTracking()
|
|
23
|
+
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/// <inheritdoc />
|
|
27
|
+
public async Task<List<{Feature}>> GetAllAsync(CancellationToken cancellationToken = default)
|
|
28
|
+
{
|
|
29
|
+
return await _dbSet
|
|
30
|
+
.AsNoTracking()
|
|
31
|
+
.OrderByDescending(x => x.CreatedAt)
|
|
32
|
+
.ToListAsync(cancellationToken);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// <inheritdoc />
|
|
36
|
+
public async Task AddAsync({Feature} entity, CancellationToken cancellationToken = default)
|
|
37
|
+
{
|
|
38
|
+
await _dbSet.AddAsync(entity, cancellationToken);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// <inheritdoc />
|
|
42
|
+
public void Update({Feature} entity)
|
|
43
|
+
{
|
|
44
|
+
_dbSet.Update(entity);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// <inheritdoc />
|
|
48
|
+
public void Remove({Feature} entity)
|
|
49
|
+
{
|
|
50
|
+
_dbSet.Remove(entity);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// <inheritdoc />
|
|
54
|
+
public async Task SaveChangesAsync(CancellationToken cancellationToken = default)
|
|
55
|
+
{
|
|
56
|
+
await context.SaveChangesAsync(cancellationToken);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#region Additional Query Methods
|
|
60
|
+
|
|
61
|
+
/// <summary>
|
|
62
|
+
/// Gets {Feature}s by status.
|
|
63
|
+
/// </summary>
|
|
64
|
+
public async Task<List<{Feature}>> GetByStatusAsync(
|
|
65
|
+
{Feature}Status status,
|
|
66
|
+
CancellationToken cancellationToken = default)
|
|
67
|
+
{
|
|
68
|
+
return await _dbSet
|
|
69
|
+
.AsNoTracking()
|
|
70
|
+
.Where(x => x.Status == status)
|
|
71
|
+
.OrderByDescending(x => x.CreatedAt)
|
|
72
|
+
.ToListAsync(cancellationToken);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// <summary>
|
|
76
|
+
/// Checks if a {Feature} with the given name exists.
|
|
77
|
+
/// </summary>
|
|
78
|
+
public async Task<bool> ExistsByNameAsync(
|
|
79
|
+
string name,
|
|
80
|
+
CancellationToken cancellationToken = default)
|
|
81
|
+
{
|
|
82
|
+
return await _dbSet
|
|
83
|
+
.AsNoTracking()
|
|
84
|
+
.AnyAsync(x => x.Name == name, cancellationToken);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// <summary>
|
|
88
|
+
/// Gets {Feature}s with pagination.
|
|
89
|
+
/// </summary>
|
|
90
|
+
public async Task<(List<{Feature}> Items, int TotalCount)> GetPagedAsync(
|
|
91
|
+
int page,
|
|
92
|
+
int pageSize,
|
|
93
|
+
CancellationToken cancellationToken = default)
|
|
94
|
+
{
|
|
95
|
+
var query = _dbSet.AsNoTracking();
|
|
96
|
+
|
|
97
|
+
var totalCount = await query.CountAsync(cancellationToken);
|
|
98
|
+
|
|
99
|
+
var items = await query
|
|
100
|
+
.OrderByDescending(x => x.CreatedAt)
|
|
101
|
+
.Skip((page - 1) * pageSize)
|
|
102
|
+
.Take(pageSize)
|
|
103
|
+
.ToListAsync(cancellationToken);
|
|
104
|
+
|
|
105
|
+
return (items, totalCount);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#endregion
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ============================================================
|
|
112
|
+
// EF CORE CONFIGURATION
|
|
113
|
+
// ============================================================
|
|
114
|
+
|
|
115
|
+
public class {Feature}Configuration : IEntityTypeConfiguration<{Feature}>
|
|
116
|
+
{
|
|
117
|
+
public void Configure(EntityTypeBuilder<{Feature}> builder)
|
|
118
|
+
{
|
|
119
|
+
builder.ToTable("{Feature}s");
|
|
120
|
+
|
|
121
|
+
builder.HasKey(x => x.Id);
|
|
122
|
+
|
|
123
|
+
builder.Property(x => x.Name)
|
|
124
|
+
.IsRequired()
|
|
125
|
+
.HasMaxLength(200);
|
|
126
|
+
|
|
127
|
+
builder.Property(x => x.Status)
|
|
128
|
+
.IsRequired()
|
|
129
|
+
.HasConversion<string>();
|
|
130
|
+
|
|
131
|
+
builder.Property(x => x.CreatedAt)
|
|
132
|
+
.IsRequired();
|
|
133
|
+
|
|
134
|
+
builder.Property(x => x.UpdatedAt);
|
|
135
|
+
|
|
136
|
+
// Indexes
|
|
137
|
+
builder.HasIndex(x => x.Name);
|
|
138
|
+
builder.HasIndex(x => x.Status);
|
|
139
|
+
builder.HasIndex(x => x.CreatedAt);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
// ==============================================================================
|
|
2
|
+
// MORPH-SPEC - Subscription Model Template
|
|
3
|
+
// Modelo de assinatura para SaaS
|
|
4
|
+
// ==============================================================================
|
|
5
|
+
|
|
6
|
+
using System.ComponentModel.DataAnnotations;
|
|
7
|
+
|
|
8
|
+
namespace {{Namespace}}.Domain.Entities;
|
|
9
|
+
|
|
10
|
+
// ==============================================================================
|
|
11
|
+
// SUBSCRIPTION ENTITY
|
|
12
|
+
// ==============================================================================
|
|
13
|
+
|
|
14
|
+
public class Subscription : BaseEntity
|
|
15
|
+
{
|
|
16
|
+
public int TenantId { get; private set; }
|
|
17
|
+
public Tenant Tenant { get; private set; } = null!;
|
|
18
|
+
|
|
19
|
+
public int PlanId { get; private set; }
|
|
20
|
+
public Plan Plan { get; private set; } = null!;
|
|
21
|
+
|
|
22
|
+
public SubscriptionStatus Status { get; private set; }
|
|
23
|
+
public BillingCycle Cycle { get; private set; }
|
|
24
|
+
|
|
25
|
+
public DateTime StartDate { get; private set; }
|
|
26
|
+
public DateTime? EndDate { get; private set; }
|
|
27
|
+
public DateTime? CancelledAt { get; private set; }
|
|
28
|
+
public DateTime NextBillingDate { get; private set; }
|
|
29
|
+
|
|
30
|
+
public decimal CurrentPrice { get; private set; }
|
|
31
|
+
public string? ExternalSubscriptionId { get; private set; } // Asaas subscription ID
|
|
32
|
+
|
|
33
|
+
public ICollection<SubscriptionPayment> Payments { get; private set; } = new List<SubscriptionPayment>();
|
|
34
|
+
|
|
35
|
+
// =========================================================================
|
|
36
|
+
// FACTORY
|
|
37
|
+
// =========================================================================
|
|
38
|
+
|
|
39
|
+
public static Subscription Create(int tenantId, int planId, BillingCycle cycle, decimal price)
|
|
40
|
+
{
|
|
41
|
+
return new Subscription
|
|
42
|
+
{
|
|
43
|
+
TenantId = tenantId,
|
|
44
|
+
PlanId = planId,
|
|
45
|
+
Status = SubscriptionStatus.PendingPayment,
|
|
46
|
+
Cycle = cycle,
|
|
47
|
+
StartDate = DateTime.UtcNow,
|
|
48
|
+
NextBillingDate = DateTime.UtcNow,
|
|
49
|
+
CurrentPrice = price,
|
|
50
|
+
CreatedAt = DateTime.UtcNow
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// =========================================================================
|
|
55
|
+
// BEHAVIORS
|
|
56
|
+
// =========================================================================
|
|
57
|
+
|
|
58
|
+
public void Activate(string externalSubscriptionId)
|
|
59
|
+
{
|
|
60
|
+
Status = SubscriptionStatus.Active;
|
|
61
|
+
ExternalSubscriptionId = externalSubscriptionId;
|
|
62
|
+
UpdatedAt = DateTime.UtcNow;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public void Suspend()
|
|
66
|
+
{
|
|
67
|
+
Status = SubscriptionStatus.Suspended;
|
|
68
|
+
UpdatedAt = DateTime.UtcNow;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public void Cancel(DateTime? endDate = null)
|
|
72
|
+
{
|
|
73
|
+
Status = SubscriptionStatus.Cancelled;
|
|
74
|
+
CancelledAt = DateTime.UtcNow;
|
|
75
|
+
EndDate = endDate ?? DateTime.UtcNow;
|
|
76
|
+
UpdatedAt = DateTime.UtcNow;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public void Renew()
|
|
80
|
+
{
|
|
81
|
+
NextBillingDate = CalculateNextBillingDate();
|
|
82
|
+
UpdatedAt = DateTime.UtcNow;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public void ChangePlan(int newPlanId, decimal newPrice)
|
|
86
|
+
{
|
|
87
|
+
PlanId = newPlanId;
|
|
88
|
+
CurrentPrice = newPrice;
|
|
89
|
+
UpdatedAt = DateTime.UtcNow;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public void AddPayment(SubscriptionPayment payment)
|
|
93
|
+
{
|
|
94
|
+
Payments.Add(payment);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// =========================================================================
|
|
98
|
+
// QUERIES
|
|
99
|
+
// =========================================================================
|
|
100
|
+
|
|
101
|
+
public bool IsActive => Status == SubscriptionStatus.Active;
|
|
102
|
+
public bool IsCancelled => Status == SubscriptionStatus.Cancelled;
|
|
103
|
+
public bool IsSuspended => Status == SubscriptionStatus.Suspended;
|
|
104
|
+
public bool IsExpired => EndDate.HasValue && EndDate.Value < DateTime.UtcNow;
|
|
105
|
+
|
|
106
|
+
public int DaysUntilRenewal => (NextBillingDate - DateTime.UtcNow).Days;
|
|
107
|
+
public bool IsNearRenewal => DaysUntilRenewal <= 3;
|
|
108
|
+
|
|
109
|
+
private DateTime CalculateNextBillingDate()
|
|
110
|
+
{
|
|
111
|
+
return Cycle switch
|
|
112
|
+
{
|
|
113
|
+
BillingCycle.Monthly => NextBillingDate.AddMonths(1),
|
|
114
|
+
BillingCycle.Quarterly => NextBillingDate.AddMonths(3),
|
|
115
|
+
BillingCycle.Yearly => NextBillingDate.AddYears(1),
|
|
116
|
+
_ => NextBillingDate.AddMonths(1)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// ==============================================================================
|
|
122
|
+
// SUBSCRIPTION PAYMENT ENTITY
|
|
123
|
+
// ==============================================================================
|
|
124
|
+
|
|
125
|
+
public class SubscriptionPayment : BaseEntity
|
|
126
|
+
{
|
|
127
|
+
public int SubscriptionId { get; private set; }
|
|
128
|
+
public Subscription Subscription { get; private set; } = null!;
|
|
129
|
+
|
|
130
|
+
public decimal Amount { get; private set; }
|
|
131
|
+
public PaymentStatus Status { get; private set; }
|
|
132
|
+
public PaymentMethod Method { get; private set; }
|
|
133
|
+
|
|
134
|
+
public DateTime DueDate { get; private set; }
|
|
135
|
+
public DateTime? PaidAt { get; private set; }
|
|
136
|
+
|
|
137
|
+
public string? ExternalPaymentId { get; private set; } // Asaas payment ID
|
|
138
|
+
public string? InvoiceUrl { get; private set; }
|
|
139
|
+
public string? BoletoUrl { get; private set; }
|
|
140
|
+
public string? PixQrCode { get; private set; }
|
|
141
|
+
public string? PixPayload { get; private set; }
|
|
142
|
+
|
|
143
|
+
// =========================================================================
|
|
144
|
+
// FACTORY
|
|
145
|
+
// =========================================================================
|
|
146
|
+
|
|
147
|
+
public static SubscriptionPayment Create(
|
|
148
|
+
int subscriptionId,
|
|
149
|
+
decimal amount,
|
|
150
|
+
PaymentMethod method,
|
|
151
|
+
DateTime dueDate)
|
|
152
|
+
{
|
|
153
|
+
return new SubscriptionPayment
|
|
154
|
+
{
|
|
155
|
+
SubscriptionId = subscriptionId,
|
|
156
|
+
Amount = amount,
|
|
157
|
+
Status = PaymentStatus.Pending,
|
|
158
|
+
Method = method,
|
|
159
|
+
DueDate = dueDate,
|
|
160
|
+
CreatedAt = DateTime.UtcNow
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// =========================================================================
|
|
165
|
+
// BEHAVIORS
|
|
166
|
+
// =========================================================================
|
|
167
|
+
|
|
168
|
+
public void SetExternalId(string externalPaymentId)
|
|
169
|
+
{
|
|
170
|
+
ExternalPaymentId = externalPaymentId;
|
|
171
|
+
UpdatedAt = DateTime.UtcNow;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public void SetPaymentUrls(string? invoiceUrl, string? boletoUrl)
|
|
175
|
+
{
|
|
176
|
+
InvoiceUrl = invoiceUrl;
|
|
177
|
+
BoletoUrl = boletoUrl;
|
|
178
|
+
UpdatedAt = DateTime.UtcNow;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public void SetPixData(string qrCode, string payload)
|
|
182
|
+
{
|
|
183
|
+
PixQrCode = qrCode;
|
|
184
|
+
PixPayload = payload;
|
|
185
|
+
UpdatedAt = DateTime.UtcNow;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public void MarkAsPaid()
|
|
189
|
+
{
|
|
190
|
+
Status = PaymentStatus.Paid;
|
|
191
|
+
PaidAt = DateTime.UtcNow;
|
|
192
|
+
UpdatedAt = DateTime.UtcNow;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
public void MarkAsOverdue()
|
|
196
|
+
{
|
|
197
|
+
Status = PaymentStatus.Overdue;
|
|
198
|
+
UpdatedAt = DateTime.UtcNow;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public void MarkAsRefunded()
|
|
202
|
+
{
|
|
203
|
+
Status = PaymentStatus.Refunded;
|
|
204
|
+
UpdatedAt = DateTime.UtcNow;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// ==============================================================================
|
|
209
|
+
// PLAN ENTITY
|
|
210
|
+
// ==============================================================================
|
|
211
|
+
|
|
212
|
+
public class Plan : BaseEntity
|
|
213
|
+
{
|
|
214
|
+
[Required]
|
|
215
|
+
[MaxLength(100)]
|
|
216
|
+
public string Name { get; private set; } = string.Empty;
|
|
217
|
+
|
|
218
|
+
[MaxLength(500)]
|
|
219
|
+
public string? Description { get; private set; }
|
|
220
|
+
|
|
221
|
+
public decimal MonthlyPrice { get; private set; }
|
|
222
|
+
public decimal YearlyPrice { get; private set; }
|
|
223
|
+
|
|
224
|
+
public int MaxUsers { get; private set; }
|
|
225
|
+
public long MaxStorageBytes { get; private set; }
|
|
226
|
+
|
|
227
|
+
public bool IsActive { get; private set; }
|
|
228
|
+
public int SortOrder { get; private set; }
|
|
229
|
+
|
|
230
|
+
public ICollection<PlanFeature> Features { get; private set; } = new List<PlanFeature>();
|
|
231
|
+
|
|
232
|
+
// =========================================================================
|
|
233
|
+
// FACTORY
|
|
234
|
+
// =========================================================================
|
|
235
|
+
|
|
236
|
+
public static Plan Create(
|
|
237
|
+
string name,
|
|
238
|
+
decimal monthlyPrice,
|
|
239
|
+
decimal yearlyPrice,
|
|
240
|
+
int maxUsers,
|
|
241
|
+
long maxStorageBytes)
|
|
242
|
+
{
|
|
243
|
+
return new Plan
|
|
244
|
+
{
|
|
245
|
+
Name = name,
|
|
246
|
+
MonthlyPrice = monthlyPrice,
|
|
247
|
+
YearlyPrice = yearlyPrice,
|
|
248
|
+
MaxUsers = maxUsers,
|
|
249
|
+
MaxStorageBytes = maxStorageBytes,
|
|
250
|
+
IsActive = true,
|
|
251
|
+
CreatedAt = DateTime.UtcNow
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// =========================================================================
|
|
256
|
+
// QUERIES
|
|
257
|
+
// =========================================================================
|
|
258
|
+
|
|
259
|
+
public decimal GetPrice(BillingCycle cycle) => cycle switch
|
|
260
|
+
{
|
|
261
|
+
BillingCycle.Monthly => MonthlyPrice,
|
|
262
|
+
BillingCycle.Quarterly => MonthlyPrice * 3 * 0.95m, // 5% discount
|
|
263
|
+
BillingCycle.Yearly => YearlyPrice,
|
|
264
|
+
_ => MonthlyPrice
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
public decimal YearlySavings => (MonthlyPrice * 12) - YearlyPrice;
|
|
268
|
+
public int YearlySavingsPercent => (int)((YearlySavings / (MonthlyPrice * 12)) * 100);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ==============================================================================
|
|
272
|
+
// PLAN FEATURE ENTITY
|
|
273
|
+
// ==============================================================================
|
|
274
|
+
|
|
275
|
+
public class PlanFeature
|
|
276
|
+
{
|
|
277
|
+
public int Id { get; private set; }
|
|
278
|
+
public int PlanId { get; private set; }
|
|
279
|
+
public Plan Plan { get; private set; } = null!;
|
|
280
|
+
|
|
281
|
+
[Required]
|
|
282
|
+
[MaxLength(100)]
|
|
283
|
+
public string Name { get; private set; } = string.Empty;
|
|
284
|
+
|
|
285
|
+
[MaxLength(200)]
|
|
286
|
+
public string? Description { get; private set; }
|
|
287
|
+
|
|
288
|
+
public bool IsIncluded { get; private set; }
|
|
289
|
+
public int? Limit { get; private set; } // null = unlimited
|
|
290
|
+
|
|
291
|
+
public static PlanFeature Create(string name, bool isIncluded, int? limit = null)
|
|
292
|
+
{
|
|
293
|
+
return new PlanFeature
|
|
294
|
+
{
|
|
295
|
+
Name = name,
|
|
296
|
+
IsIncluded = isIncluded,
|
|
297
|
+
Limit = limit
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ==============================================================================
|
|
303
|
+
// ENUMS
|
|
304
|
+
// ==============================================================================
|
|
305
|
+
|
|
306
|
+
public enum SubscriptionStatus
|
|
307
|
+
{
|
|
308
|
+
PendingPayment,
|
|
309
|
+
Active,
|
|
310
|
+
Suspended,
|
|
311
|
+
Cancelled,
|
|
312
|
+
Expired
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
public enum BillingCycle
|
|
316
|
+
{
|
|
317
|
+
Monthly,
|
|
318
|
+
Quarterly,
|
|
319
|
+
Yearly
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public enum PaymentStatus
|
|
323
|
+
{
|
|
324
|
+
Pending,
|
|
325
|
+
Paid,
|
|
326
|
+
Overdue,
|
|
327
|
+
Refunded,
|
|
328
|
+
Cancelled
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public enum PaymentMethod
|
|
332
|
+
{
|
|
333
|
+
Pix,
|
|
334
|
+
Boleto,
|
|
335
|
+
CreditCard
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// ==============================================================================
|
|
339
|
+
// BASE ENTITY
|
|
340
|
+
// ==============================================================================
|
|
341
|
+
|
|
342
|
+
public abstract class BaseEntity
|
|
343
|
+
{
|
|
344
|
+
public int Id { get; protected set; }
|
|
345
|
+
public DateTime CreatedAt { get; protected set; }
|
|
346
|
+
public DateTime? UpdatedAt { get; protected set; }
|
|
347
|
+
}
|