import { MigrationInterface, QueryRunner } from 'typeorm';

export class updateTask1703053155925 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',
        }),
        '00000000-0000-0000-0000-000000000010',
      ],
    );
    await queryRunner.query(
      `
            UPDATE asset_block_comps
            SET computed_at = NULL
            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,
          'attr\\index': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-000000000011',
          },
          '\\archivedat': null,
          '\\assignedto': null,
          '\\taskcolumn': null,
          'index\\color': 10,
          'index\\index': 8,
          'title\\color': '[[t:Color]]',
          'title\\index': '[[t:Index]]',
          '\\iscompleted': null,
          'index\\result': 9,
          'title\\result': '[[t:Result]]',
          'attr\\archivedat': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-000000000009',
          },
          'attr\\assignedto': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-000000000008',
          },
          'attr\\taskcolumn': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-000000000007',
          },
          'attr\\iscompleted': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-000000000003',
          },
          'index\\archivedat': 7,
          'index\\assignedto': 5,
          'index\\taskcolumn': 3,
          'title\\archivedat': '[[t:ArchivedAt]]',
          'title\\assignedto': '[[t:AssignedTo]]',
          'title\\taskcolumn': '[[t:TaskColumn]]',
          'index\\iscompleted': 6,
          'title\\iscompleted': '[[t:IsCompleted]]',
        }),
        '00000000-0000-0000-0000-000000000010',
      ],
    );
    await queryRunner.query(
      `
            UPDATE asset_block_comps
            SET computed_at = NULL
            WHERE asset_id = '00000000-0000-0000-0000-000000000010' AND project_id = 1 AND block_key = 1
        `,
    );
  }
}
