import { Injectable } from '@nestjs/common';
import { PrismaService } from '@core/database/prisma/prisma.service';
import { Country } from '@prisma/client';

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

  list(region?: string): Promise<Country[]> {
    return this.prisma.country.findMany({
      where: { enabled: true, ...(region ? { region } : {}) },
      orderBy: { code: 'asc' },
    });
  }

  findByCode(code: string): Promise<Country | null> {
    return this.prisma.country.findUnique({ where: { code } });
  }
}
