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

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

  async getSettings() {
    // Always returns a row — creates defaults on first call
    return this.prisma.appSettings.upsert({
      where: { id: 'default' },
      update: {},
      create: { id: 'default' },
    });
  }

  async updateSettings(dto: {
    clubName?: string;
    tagline?: string;
    logoUrl?: string;
    primaryColor?: string;
  }) {
    return this.prisma.appSettings.upsert({
      where: { id: 'default' },
      update: dto,
      create: { id: 'default', ...dto },
    });
  }
}
