import { MigrationInterface, QueryRunner } from 'typeorm';

export class projectSettingsAndTaskColor1699957352607
  implements MigrationInterface
{
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `
            UPDATE asset_blocks
            SET props = $1
            WHERE asset_id = '00000000-0000-0000-0000-000000000010'
            AND project_id = 1
            AND block_key = 1
        `,
      [
        `{"\\\\index": null, "\\\\result": null, "attr\\\\index": {"name": null, "title": null, "assetId": "00000000-0000-0000-0000-000000000011"}, "\\\\archivedat": null, "\\\\assignedto": null, "\\\\taskcolumn": null, "index\\\\index": 8, "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]]", "\\\\color": null, "index\\\\color": 10, "title\\\\color": "[[t:Color]]"}`,
      ],
    );
    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`,
    );
    await queryRunner.query(`
            INSERT INTO asset_block_keys(project_id, block_key, block_name, block_title, block_type)
            SELECT id, 10001, 'game-pulse', '', 'props'
            FROM projects;
    `);
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, is_abstract, created_at, updated_at, deleted_at, creator_user_id, scope_id) 
        VALUES (
            '00000000-0000-0000-0000-100000000002', 
            '00000000-0000-0000-0000-000000000001', 
            '{}', 
            1, 
            null, 
            '[[t:ProjectProps]]', 
            'tools-fill', 
            false, 
            '2023-10-06 05:57:16.190664 +00:00', 
            '2023-10-15 22:53:28.942486 +00:00', 
            null, 
            null, 
            3);
    `);
    await queryRunner.query(`
        INSERT INTO public.assets (id, workspace_id, parent_ids, project_id, name, title, icon, is_abstract, created_at, updated_at, deleted_at, creator_user_id, scope_id) 
        VALUES (
            '00000000-0000-0000-0000-100000000003', 
            '00000000-0000-0000-0000-000000000001', 
            '{00000000-0000-0000-0000-000000000001}', 
            1,
            null, 
            '[[t:AttributeUsedForAssetsForAttribute]]', 
            'grid-fill', 
            false, 
            '2023-10-15 22:23:11.832195 +00:00', 
            '2023-10-15 22:53:28.942486 +00:00', 
            null, 
            null, 
            3
        );
    `);
    await queryRunner.query(
      `
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) 
        VALUES (
            1, 10001, 
            '00000000-0000-0000-0000-100000000002', 
            '[[t:GamePulseProps]]', 
            $1, 
            '2023-10-15 22:21:37.818253 +00:00', 
            '2023-10-15 22:22:24.629625 +00:00',
            1, 
            false);    
    `,
      [
        '{"\\\\autogenerate": true, "attr\\\\autogenerate": {"name": null, "title": null, "assetId": "00000000-0000-0000-0000-100000000003"}, "title\\\\autogenerate": "[[t:AutogeneratePulseEvents]]", "index\\\\autogenerate": 1}',
      ],
    );
    await queryRunner.query(
      `
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 1, '00000000-0000-0000-0000-100000000003', '[[t:Info]]', '{"\\\\type": "checkbox"}', '2023-10-15 22:27:04.820769 +00:00', '2023-10-15 22:27:04.820769 +00:00', null, false);
        INSERT INTO public.asset_blocks (project_id, block_key, asset_id, title, props, created_at, updated_at, index, has_formula) VALUES (1, 2, '00000000-0000-0000-0000-100000000003', '[[t:Additional]]', '{"\\\\hint": "[[t:AttributeAutogeneratePulseEventsForProjectPropsHint]]"}', '2023-10-15 22:24:48.318445 +00:00', '2023-10-15 22:24:56.849936 +00:00', null, false);
        `,
    );
    await queryRunner.query(`
        INSERT INTO asset_comps(project_id, id)
        SELECT project_id, id
        FROM assets
        ON CONFLICT DO NOTHING;
        INSERT INTO asset_block_comps(project_id, asset_id, block_key)
        SELECT project_id, asset_id, block_key
        FROM asset_blocks
        ON CONFLICT DO NOTHING;
    `);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `
            UPDATE asset_blocks
            SET props = $1
            WHERE asset_id = '00000000-0000-0000-0000-000000000010'
            AND project_id = 1
            AND block_key = 1
        `,
      [
        `{"\\\\index": null, "\\\\result": null, "attr\\\\index": {"name": null, "title": null, "assetId": "00000000-0000-0000-0000-000000000011"}, "\\\\archivedat": null, "\\\\assignedto": null, "\\\\taskcolumn": null, "index\\\\index": 8, "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]]"}`,
      ],
    );
    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`,
    );
    await queryRunner.query(`
        DELETE FROM assets WHERE id = '00000000-0000-0000-0000-100000000002'
    `);
    await queryRunner.query(`
        DELETE FROM assets WHERE id = '00000000-0000-0000-0000-100000000003'
    `);
    await queryRunner.query(`
            DELETE FROM asset_block_keys
            WHERE block_key = 10001
    `);
  }
}
