import { Inject, Injectable } from "@nestjs/common";
import * as schema from "drizzle/schema";
import { countDistinct, and, eq } from 'drizzle-orm';
import { NodePgDatabase } from "drizzle-orm/node-postgres";

@Injectable()
export class AccountRepo {
  constructor(@Inject('DRIZZLE') private readonly db: NodePgDatabase<typeof schema>) {}

  async checkDuplication(type: 'email' | 'accountId', value: string) {
    const result = await this
    .db
    .select({ count: countDistinct(schema.account[type])})
    .from(schema.account)
    .where(
      eq(schema.account[type], value)
    );

    return result[0].count;
  }

  async signup(
    accountId: string,
    name: string,
    nickname: string,
    email: string,
    password: string
  ) {
    return this
    .db
    .insert(schema.account)
    .values({
      accountId: accountId,
      name: name,
      nickname: nickname,
      email: email,
      password: password
    });
  }

  async 
}