import { MigrationInterface, QueryRunner } from 'typeorm';

export class addWatchersToTasks1710886963802 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `
            UPDATE asset_blocks
            SET props = $1
            WHERE asset_id = $2 AND project_id = 1 AND block_key = 1
        `,
      [
        JSON.stringify({
          '\\color': null,
          '\\index': null,
          '\\result': null,
          '\\category': null,
          '\\actualtime': null,
          '\\archivedat': null,
          '\\assignedto': null,
          '\\taskcolumn': null,
          'index\\color': 10,
          'index\\index': 8,
          'title\\color': '[[t:Color]]',
          'title\\index': '[[t:Index]]',
          '\\iscompleted': null,
          '\\scheduledat': null,
          'index\\result': 9,
          'title\\result': '[[t:Result]]',
          '\\estimatedtime': null,
          'index\\category': 12,
          'title\\category': '[[t:Category]]',
          'field\\color\\type': 'string',
          'index\\actualtime': 14,
          'index\\archivedat': 7,
          'index\\assignedto': 5,
          'index\\taskcolumn': 3,
          'title\\actualtime': '[[t:ActualTime]]',
          'title\\archivedat': '[[t:ArchivedAt]]',
          'title\\assignedto': '[[t:AssignedTo]]',
          'title\\taskcolumn': '[[t:TaskColumn]]',
          'index\\iscompleted': 6,
          'index\\scheduledat': 11,
          'title\\iscompleted': '[[t:IsCompleted]]',
          'title\\scheduledat': '[[t:ScheduledAt]]',
          'index\\estimatedtime': 13,
          'title\\estimatedtime': '[[t:EstimatedTime]]',
          'field\\archivedat\\type': 'buttonDateTime',
          'field\\assignedto\\type': 'projectUser',
          'field\\taskcolumn\\type': 'taskColumn',
          'field\\iscompleted\\type': 'checkbox',
          'field\\scheduledat\\type': 'dateTime',
          '\\watchers': [],
          'index\\watchers': 15,
          'title\\watchers': '[[t:Watchers]]',
        }),
        '00000000-0000-0000-0000-000000000010',
      ],
    );
    await queryRunner.query(
      `
          UPDATE asset_block_comps
          SET dirty_at = NOW()
          WHERE asset_id = '00000000-0000-0000-0000-000000000010'
          AND project_id = 1
          AND block_key = 1`,
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `
            UPDATE asset_blocks
            SET props = $1
            WHERE asset_id = $2 AND project_id = 1 AND block_key = 1
        `,
      [
        JSON.stringify({
          '\\color': null,
          '\\index': null,
          '\\result': null,
          '\\category': null,
          '\\actualtime': null,
          '\\archivedat': null,
          '\\assignedto': null,
          '\\taskcolumn': null,
          'index\\color': 10,
          'index\\index': 8,
          'title\\color': '[[t:Color]]',
          'title\\index': '[[t:Index]]',
          '\\iscompleted': null,
          '\\scheduledat': null,
          'index\\result': 9,
          'title\\result': '[[t:Result]]',
          '\\estimatedtime': null,
          'index\\category': 12,
          'title\\category': '[[t:Category]]',
          'field\\color\\type': 'string',
          'index\\actualtime': 14,
          'index\\archivedat': 7,
          'index\\assignedto': 5,
          'index\\taskcolumn': 3,
          'title\\actualtime': '[[t:ActualTime]]',
          'title\\archivedat': '[[t:ArchivedAt]]',
          'title\\assignedto': '[[t:AssignedTo]]',
          'title\\taskcolumn': '[[t:TaskColumn]]',
          'index\\iscompleted': 6,
          'index\\scheduledat': 11,
          'title\\iscompleted': '[[t:IsCompleted]]',
          'title\\scheduledat': '[[t:ScheduledAt]]',
          'index\\estimatedtime': 13,
          'title\\estimatedtime': '[[t:EstimatedTime]]',
          'field\\archivedat\\type': 'buttonDateTime',
          'field\\assignedto\\type': 'projectUser',
          'field\\taskcolumn\\type': 'taskColumn',
          'field\\iscompleted\\type': 'checkbox',
          'field\\scheduledat\\type': 'dateTime',
        }),
        '00000000-0000-0000-0000-000000000010',
      ],
    );
    await queryRunner.query(
      `
          UPDATE asset_block_comps
          SET dirty_at = NOW()
          WHERE asset_id = '00000000-0000-0000-0000-000000000010'
          AND project_id = 1
          AND block_key = 1`,
    );
  }
}
