import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Seller } from './entities/seller.entity';

@Injectable()
export class SellerVerificationService {
  constructor(
    @InjectRepository(Seller)
    private readonly sellerRepository: Repository<Seller>,
  ) {}

  async verifyBusinessRegistration(sellerId: string): Promise<boolean> {
    const seller = await this.sellerRepository.findOne({ where: { id: sellerId } });
    if (!seller) return false;
    
    // Custom verification logic (manual admin review)
    // In production, this would trigger admin notification
    return seller.registrationNumber && seller.taxNumber ? true : false;
  }

  async validateTaxId(taxNumber: string, country: string): Promise<boolean> {
    // Custom tax ID validation per country
    const patterns: Record<string, RegExp> = {
      'US': /^\d{2}-\d{7}$/,
      'GB': /^[A-Z]{2}\d{6}[A-Z]$/,
    };
    
    const pattern = patterns[country];
    return pattern ? pattern.test(taxNumber) : true;
  }
}