import { Injectable } from '@nestjs/common';
import { PrismaService } from '../../../prisma/prisma.service';

@Injectable()
export class FiscalYearsService {
  constructor(private readonly prisma: PrismaService) {}

  create(data: { complexId: string; label: string; startDate: Date; endDate: Date }) {
    return this.prisma.fiscalYear.create({ data });
  }

  findByComplex(complexId: string) {
    return this.prisma.fiscalYear.findMany({
      where: { complexId },
      orderBy: { startDate: 'desc' },
    });
  }

  close(id: string) {
    return this.prisma.fiscalYear.update({ where: { id }, data: { status: 'CLOSED' } });
  }
}
