import { DataSource } from 'typeorm';

const tableName = 'workspace';

export const SeedWorkspaceId = '20202020-1c25-4d02-bf25-6aeccf7ea419';

export const seedWorkspaces = async (
  workspaceDataSource: DataSource,
  schemaName: string,
  workspaceId: string,
) => {
  await workspaceDataSource
    .createQueryBuilder()
    .insert()
    .into(`${schemaName}.${tableName}`, [
      'id',
      'displayName',
      'domainName',
      'inviteHash',
      'logo',
    ])
    .orIgnore()
    .values([
      {
        id: workspaceId,
        displayName: 'Apple',
        domainName: 'apple.dev',
        inviteHash: 'apple.dev-invite-hash',
        logo: 'data:image/png;base64,[encoded data, 5804 characters]',
      },
    ])
    .execute();
};

export const deleteWorkspaces = async (
  workspaceDataSource: DataSource,
  schemaName: string,
  workspaceId: string,
) => {
  await workspaceDataSource
    .createQueryBuilder()
    .delete()
    .from(`${schemaName}.${tableName}`)
    .where(`${tableName}."id" = :id`, { id: workspaceId })
    .execute();
};
