import { MigrationInterface, QueryRunner } from 'typeorm';

export class tuneTypes1703802142903 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({
          '\\genre': null,
          '\\developer': null,
          '\\coverimage': null,
          'index\\genre': 1,
          'title\\genre': '[[t:Genre]]',
          '\\releasedate': null,
          'index\\developer': 2,
          'title\\developer': '[[t:Developer]]',
          'index\\coverimage': 4,
          'title\\coverimage': '[[t:CoverImage]]',
          'index\\releasedate': 3,
          'title\\releasedate': '[[t:ReleaseDate]]',
          'field\\coverimage\\type': 'attachment',
          'field\\coverimage\\hint': '[[t:AttributeCoverImageHint]]',
        }),
        '00000000-0000-0000-0000-100000000000',
      ],
    );
    await queryRunner.query(
      `
                    UPDATE asset_block_comps
                    SET computed_at = NULL
                    WHERE asset_id = '00000000-0000-0000-0000-100000000000' AND project_id = 1 AND block_key = 1
                `,
    );
    await queryRunner.query(
      `
                UPDATE asset_blocks
                SET props = $1
                WHERE asset_id = $2 AND project_id = 1 AND block_key = 1
            `,
      [
        JSON.stringify({
          '\\fields': [0, 1, 2, 3, 4, 5],
          '\\fields\\4': null,
          '\\fields\\5': null,
          '\\fields\\0\\name': 'name',
          '\\fields\\0\\type': 'string',
          '\\fields\\1\\name': 'title',
          '\\fields\\1\\type': 'string',
          '\\fields\\2\\name': 'type',
          '\\fields\\2\\type': 'attributeType',
          '\\fields\\3\\name': 'multiple',
          '\\fields\\3\\type': 'checkbox',
          '\\fields\\4\\name': 'hidden',
          '\\fields\\4\\type': 'checkbox',
          '\\fields\\5\\name': 'params',
          '\\fields\\5\\type': 'fieldParams',
          '\\fields\\0\\title': '[[t:StructureFieldName]]',
          '\\fields\\1\\title': '[[t:StructureFieldTitle]]',
          '\\fields\\2\\title': '[[t:StructureFieldType]]',
          '\\fields\\3\\title': '[[t:StructureFieldMultiple]]',
          '\\fields\\4\\title': '[[t:StructureFieldHidden]]',
          '\\fields\\5\\title': '[[t:StructureFieldParams]]',
          '\\fields\\0\\hidden': false,
          '\\fields\\1\\hidden': false,
          '\\fields\\2\\hidden': false,
          '\\fields\\3\\hidden': false,
          '\\fields\\4\\hidden': false,
          '\\fields\\5\\hidden': false,
          '\\fields\\0\\multiple': false,
          '\\fields\\1\\multiple': false,
          '\\fields\\2\\multiple': false,
          '\\fields\\3\\multiple': false,
          '\\fields\\4\\multiple': false,
          '\\fields\\5\\multiple': false,
        }),
        '00000000-0000-0000-0000-000000000021',
      ],
    );
    await queryRunner.query(
      `
                UPDATE asset_block_comps
                SET computed_at = NULL
                WHERE asset_id = '00000000-0000-0000-0000-000000000021' 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({
          '\\fields': [0, 1, 2, 3, 4, 5],
          '\\fields\\4': null,
          '\\fields\\5': null,
          '\\fields\\0\\name': 'name',
          '\\fields\\0\\type': 'string',
          '\\fields\\1\\name': 'title',
          '\\fields\\1\\type': 'string',
          '\\fields\\2\\name': 'type',
          '\\fields\\2\\type': 'attributeType',
          '\\fields\\3\\name': 'multiple',
          '\\fields\\3\\type': 'checkbox',
          '\\fields\\4\\name': 'hidden',
          '\\fields\\4\\type': 'checkbox',
          '\\fields\\5\\name': 'params',
          '\\fields\\5\\type': 'fieldParams',
          '\\fields\\0\\title': '[[t:StructureFieldName]]',
          '\\fields\\1\\title': '[[t:StructureFieldTitle]]',
          '\\fields\\2\\title': '[[t:StructureFieldType]]',
          '\\fields\\3\\title': '[[t:StructureFieldMultiple]]',
          '\\fields\\4\\title': 'Скрыто',
          '\\fields\\5\\title': 'Параметры',
          '\\fields\\0\\hidden': false,
          '\\fields\\1\\hidden': false,
          '\\fields\\2\\hidden': false,
          '\\fields\\3\\hidden': false,
          '\\fields\\4\\hidden': false,
          '\\fields\\5\\hidden': false,
          '\\fields\\0\\multiple': false,
          '\\fields\\1\\multiple': false,
          '\\fields\\2\\multiple': false,
          '\\fields\\3\\multiple': false,
          '\\fields\\4\\multiple': false,
          '\\fields\\5\\multiple': false,
        }),
        '00000000-0000-0000-0000-000000000021',
      ],
    );
    await queryRunner.query(
      `
                UPDATE asset_block_comps
                SET computed_at = NULL
                WHERE asset_id = '00000000-0000-0000-0000-000000000021' AND project_id = 1 AND block_key = 1
            `,
    );
    await queryRunner.query(
      `
                  UPDATE asset_blocks
                  SET props = $1
                  WHERE asset_id = $2 AND project_id = 1 AND block_key = 1
              `,
      [
        JSON.stringify({
          '\\genre': null,
          '\\developer': null,
          '\\coverimage': null,
          'index\\genre': 1,
          'title\\genre': '[[t:Genre]]',
          '\\releasedata': null,
          'attr\\coverimage': {
            name: null,
            title: null,
            assetId: '00000000-0000-0000-0000-100000000001',
          },
          'index\\developer': 2,
          'title\\developer': '[[t:Developer]]',
          'index\\coverimage': 4,
          'title\\coverimage': '[[t:CoverImage]]',
          'index\\releasedata': 3,
          'title\\releasedata': '[[t:ReleaseDate]]',
        }),
        '00000000-0000-0000-0000-100000000000',
      ],
    );
    await queryRunner.query(
      `
                  UPDATE asset_block_comps
                  SET computed_at = NULL
                  WHERE asset_id = '00000000-0000-0000-0000-100000000000' AND project_id = 1 AND block_key = 1
              `,
    );
  }
}
