namespace TaxBaik.Infrastructure.Repositories; using Dapper; using TaxBaik.Domain.Entities; using TaxBaik.Domain.Interfaces; public class TaxProfileRepository(IDbConnectionFactory connectionFactory) : BaseRepository(connectionFactory), ITaxProfileRepository { public async Task CreateAsync(TaxProfile profile, CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryFirstAsync( @"INSERT INTO tax_profiles (client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at) VALUES (@ClientId, @BusinessRegistration, @BusinessType, @EstablishmentDate, @AnnualRevenueRange, @EmployeeCount, @AccountingMethod, @FiscalYearEnd, @LastFilingDate, @NextFilingDueDate, @TaxRiskLevel, @PreviousAuditHistory, @SpecialNotes, NOW(), NOW()) RETURNING id", profile); } public async Task GetByIdAsync(int id, CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryFirstOrDefaultAsync( @"SELECT id, client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at FROM tax_profiles WHERE id = @Id", new { Id = id }); } public async Task> GetAllAsync(CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryAsync( @"SELECT id, client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at FROM tax_profiles ORDER BY id DESC"); } public async Task GetByClientIdAsync(int clientId, CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryFirstOrDefaultAsync( @"SELECT id, client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at FROM tax_profiles WHERE client_id = @ClientId", new { ClientId = clientId }); } public async Task UpdateAsync(TaxProfile profile, CancellationToken cancellationToken = default) { using var conn = Conn(); await conn.ExecuteAsync( @"UPDATE tax_profiles SET business_registration = @BusinessRegistration, business_type = @BusinessType, establishment_date = @EstablishmentDate, annual_revenue_range = @AnnualRevenueRange, employee_count = @EmployeeCount, accounting_method = @AccountingMethod, fiscal_year_end = @FiscalYearEnd, last_filing_date = @LastFilingDate, next_filing_due_date = @NextFilingDueDate, tax_risk_level = @TaxRiskLevel, previous_audit_history = @PreviousAuditHistory, special_notes = @SpecialNotes, updated_at = NOW() WHERE id = @Id", profile); } public async Task> GetByRiskLevelAsync(string riskLevel, CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryAsync( @"SELECT id, client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at FROM tax_profiles WHERE tax_risk_level = @RiskLevel ORDER BY client_id", new { RiskLevel = riskLevel }); } public async Task> GetUpcomingFilingDuesAsync(DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default) { using var conn = Conn(); return await conn.QueryAsync( @"SELECT id, client_id, business_registration, business_type, establishment_date, annual_revenue_range, employee_count, accounting_method, fiscal_year_end, last_filing_date, next_filing_due_date, tax_risk_level, previous_audit_history, special_notes, created_at, updated_at FROM tax_profiles WHERE next_filing_due_date BETWEEN @StartDate AND @EndDate ORDER BY next_filing_due_date", new { StartDate = startDate, EndDate = endDate }); } }