using General_Ledger_Service.Infra; using General_Ledger_Service.Interfaces.Repositories; using General_Ledger_Service.Models; using Microsoft.EntityFrameworkCore; namespace General_Ledger_Service.Repositories { public class FiscalCalendarRepository(AppDBContext context) : IFiscalCalendarRepository { private readonly AppDBContext _context = context; public Task GetFiscalYearByIdAsync(int fiscalYearId) => RepositoryHelpers.GetByIdAsync(_context.FiscalYears, fiscalYearId); public Task HasOverlappingFiscalYearRangeAsync(DateOnly startDate, DateOnly endDate) => RepositoryHelpers.ExistsAsync(_context.FiscalYears, fy => startDate <= fy.EndDate && endDate >= fy.StartDate); public Task AddFiscalYearAsync(FiscalYear fiscalYear) => RepositoryHelpers.AddAsync(_context.FiscalYears, fiscalYear); public Task GetPeriodByIdAsync(int periodId) => RepositoryHelpers.GetByIdAsync(_context.AccountingPeriods, periodId); public async Task GetPeriodByDateAsync(DateOnly date) => await _context.AccountingPeriods .FirstOrDefaultAsync(p => p.StartDate <= date && p.EndDate >= date); public async Task> GetPeriodsByFiscalYearIdAsync(int fiscalYearId) => await _context.AccountingPeriods .Where(p => p.FiscalYearId == fiscalYearId) .OrderBy(p => p.PeriodNumber) .ToListAsync(); public async Task AddPeriodRangeAsync(IEnumerable periods) => await _context.AccountingPeriods.AddRangeAsync(periods); public Task AddPeriodLockLogAsync(PeriodLockLog log) => RepositoryHelpers.AddAsync(_context.PeriodLockLogs, log); } }